Skip to content

Commit

Permalink
Merge pull request #42 from Saifullah-dev/feature/backend
Browse files Browse the repository at this point in the history
Feature/backend
  • Loading branch information
Saifullah-dev authored Aug 30, 2024
2 parents b4515fb + 144874e commit 816b1c2
Show file tree
Hide file tree
Showing 68 changed files with 2,434 additions and 267 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ jobs:
- uses: actions/setup-node@v4
with:
node-version: "lts/*"
- run: npm ci
- run: npm run build
- run: npm audit signatures
- run: cd frontend && npm ci
- run: cd frontend && npm run build
- run: cd frontend && npm audit signatures
- name: Release
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
NPM_TOKEN: ${{secrets.NPM_TOKEN}}
run: npx semantic-release
run: cd frontend && npx semantic-release
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

backend/.vscode/*
!backend/.vscode/launch.json
backend/uploads/*
!backend/uploads/.gitkeep
.env
node_modules
dist
Expand Down
26 changes: 14 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,18 @@ function App() {
const [files, setFiles] = useState([
{
name: "Documents",
isDirectory: true,
path: "", // Root directory
isDirectory: true, // Folder
path: "/Documents", // Located in Root directory
},
{
name: "Pictures",
isDirectory: true,
path: "", // Root directory
isDirectory: true, // Folder
path: "/Pictures", // Located in Root directory
},
{
name: "Pic.png",
isDirectory: false,
path: "/Pictures", // Located inside the "Pictures" folder
isDirectory: false, // File
path: "/Pictures/Pic.png", // Located inside the "Pictures" folder
},
]);

Expand All @@ -60,13 +60,15 @@ function App() {
| Name | Type | Description |
|-----------------|------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------|
| `files` | `Array<{ name: string, isDirectory: boolean, path: string }>` | An array of file and folder objects representing the current directory structure. Each object includes `name`, `isDirectory`, and `path` properties. |
| `isLoading` | `boolean` | A boolean indicating whether the application is currently performing an operation, such as creating, renaming, or deleting a file/folder. Displays a loading state if `true`. |
| `isLoading` | `boolean` | A boolean state indicating whether the application is currently performing an operation, such as creating, renaming, or deleting a file/folder. Displays a loading state if set `true`. |
| `fileUploadConfig`| `{ url: string; headers?: { [key: string]: string } }` | Configuration object for file uploads. It includes the upload URL (`url`) and an optional `headers` object for setting custom HTTP headers in the upload request. The `headers` object can accept any standard or custom headers required by the server. Example: `{ url: "https://example.com/fileupload", headers: { Authorization: "Bearer" + TOKEN, "X-Custom-Header": "value" } }` |
| `onCreateFolder`| `(files: { name: string, isDirectory: boolean, path: string }[], folderName: string, folderPath: string) => void` | A callback function triggered when a new folder is created. Update the `files` state to include the new folder in the specified path. |
| `onRename` | `(files: { name: string, isDirectory: boolean, path: string }[], selectedFile: { name: string, isDirectory: boolean, path: string }, newName: string) => void` | A callback function triggered when a file or folder is renamed. Update the `files` state to reflect the new name for the specified file or folder. |
| `onDelete` | `(files: { name: string, isDirectory: boolean, path: string }[], file: { name: string, isDirectory: boolean, path: string }) => void` | A callback function triggered when a file or folder is deleted. Update the `files` state to remove the specified file or folder from the structure. |
| `onPaste` | `(files: { name: string, isDirectory: boolean, path: string }[], pastePath: string, clipBoard: { isMoving: boolean, files: { name: string, isDirectory: boolean, path: string, children?: { name: string, isDirectory: boolean, path: string }[] }[] }) => void` | A callback function triggered when a file or folder is pasted (moved or copied). Update the files state to reflect the new location of the pasted items based on the clipBoard data. |
| `onRefresh` | `() => void` | A callback function triggered when the file manager is refreshed. Use this to reload or refresh the `files` state to reflect any changes or updates. |
| onCreateFolder | (name: string, parentFolder: { name: string, isDirectory: boolean, path: string }) => void | A callback function triggered when a new folder is created. Use this function to update the files state to include the new folder under the specified parent folder using create folder API call to your server. |
| `onFileUploading` | `(file: { name: string, isDirectory: boolean, path: string }, parentFolder: { name: string, isDirectory: boolean, path: string }) => { [key: string]: any }` | A callback function triggered during the file upload process. You can also return an object with key-value pairs that will be appended to the `FormData` along with the file being uploaded. The object can contain any number of valid properties. |
| `onFileUploaded` | `(response: { [key: string]: any }) => void` | A callback function triggered after a file is successfully uploaded. Provides JSON `response` holding uploaded file details, use it to extracts the uploaded file details and add it to the `files` state e.g. ``setFiles((prev) => [...prev, JSON.parse(response)]);`` |
| onRename | (file: { name: string, isDirectory: boolean, path: string }, newName: string) => void | A callback function triggered when a file or folder is renamed. |
| onDelete | (file: { name: string, isDirectory: boolean, path: string }) => void | A callback function triggered when a file or folder is deleted. |
| onPaste | (sourceItem: { name: string, isDirectory: boolean, path: string }, destinationFolder: { name: string, isDirectory: boolean, path: string }, operationType: "copy" or "move") => void | A callback function triggered when a file or folder is pasted into a new location. Depending on operationType, use this to either copy or move the sourceItem to the destinationFolder, updating the files state accordingly. |
| `onRefresh` | `() => void` | A callback function triggered when the file manager is refreshed. Use this to refresh the `files` state to reflect any changes or updates. |

## Contributing

Expand Down
15 changes: 15 additions & 0 deletions backend/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"skipFiles": ["<node_internals>/**"],
"program": "${file}/server.js"
}
]
}
16 changes: 16 additions & 0 deletions backend/config/db.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const mongoose = require("mongoose");
const dotenv = require("dotenv");

dotenv.config();

const connectDB = async () => {
try {
await mongoose.connect(process.env.MONGO_URI);
console.log("MongoDB connected");
} catch (error) {
console.error("MongoDB connection failed:", error.message);
process.exit(1);
}
};

module.exports = connectDB;
36 changes: 36 additions & 0 deletions backend/config/multer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
const multer = require("multer");
const path = require("path");
const FileSystem = require("../models/FileSystem");
const fs = require("fs");

const storage = multer.diskStorage({
destination: async (req, file, cb) => {
let uploadPath = path.join(__dirname, "../uploads");

if (req.body.parentId) {
try {
const parentFolder = await FileSystem.findById(req.body.parentId);
if (!parentFolder || !parentFolder.isDirectory) {
return cb(new Error("Invalid parentId!"), false);
}
uploadPath = path.join(__dirname, "../uploads", parentFolder.path);
} catch (error) {
return cb(error, false);
}
}

const fullFilePath = path.join(uploadPath, file.originalname);
if (fs.existsSync(fullFilePath)) {
return cb(new multer.MulterError("File already exists!", file), false);
}

cb(null, uploadPath);
},
filename: (req, file, cb) => {
cb(null, file.originalname);
},
});

const upload = multer({ storage });

module.exports = upload;
Loading

0 comments on commit 816b1c2

Please sign in to comment.