Spaces:
Running
Running
Update app.js
Browse files
app.js
CHANGED
|
@@ -57,7 +57,7 @@ app.post("/upload", upload.single("file"), (req, res) => {
|
|
| 57 |
}
|
| 58 |
|
| 59 |
const filePath = req.file.filename;
|
| 60 |
-
const customExpiration = req.body.expires_in ? parseInt(req.body.expires_in) * 1000 : EXPIRATION_TIME;
|
| 61 |
const expiresAt = Date.now() + customExpiration;
|
| 62 |
fileData[filePath] = {
|
| 63 |
isPrivate: false,
|
|
@@ -83,7 +83,7 @@ app.post("/upload", upload.single("file"), (req, res) => {
|
|
| 83 |
file_type: req.file.mimetype,
|
| 84 |
uploadTime: Date.now(),
|
| 85 |
file_url: `${req.protocol}://${req.get("host")}/files/${filePath}`,
|
| 86 |
-
|
| 87 |
// Format sesuai sisa waktu
|
| 88 |
});
|
| 89 |
});
|
|
@@ -101,7 +101,7 @@ app.get("/files/browse", (req, res) => {
|
|
| 101 |
const paginatedFiles = publicFiles.slice(startIndex, endIndex).map(filename => ({
|
| 102 |
filename,
|
| 103 |
file_url: `${req.protocol}://${req.get("host")}/files/${filename}`,
|
| 104 |
-
expires_in: fileData[filename]?.
|
| 105 |
file_size: fileData[filename]?.fileSize,
|
| 106 |
file_type: fileData[filename]?.file_type,
|
| 107 |
uploadTime: fileData[filename]?.uploadTimeFormat
|
|
@@ -137,24 +137,30 @@ app.get("/", (req, res) => {
|
|
| 137 |
endpoint: "/upload",
|
| 138 |
description: "Upload a file",
|
| 139 |
body: "FormData (key: file)",
|
|
|
|
| 140 |
response: {
|
| 141 |
success: true,
|
| 142 |
-
file_url: "
|
| 143 |
-
expires_in: "
|
| 144 |
}
|
| 145 |
},
|
| 146 |
list_files: {
|
| 147 |
method: "GET",
|
| 148 |
-
endpoint: "/files",
|
| 149 |
description: "Get all uploaded files",
|
| 150 |
response: {
|
| 151 |
success: true,
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 158 |
}
|
| 159 |
},
|
| 160 |
delete_file: {
|
|
|
|
| 57 |
}
|
| 58 |
|
| 59 |
const filePath = req.file.filename;
|
| 60 |
+
const customExpiration = req.body.expires_in ? parseInt(req.body.expires_in) * 1000 : req.params.expires_in ? parseInt(req.params.expires_in) * 1000 : EXPIRATION_TIME;
|
| 61 |
const expiresAt = Date.now() + customExpiration;
|
| 62 |
fileData[filePath] = {
|
| 63 |
isPrivate: false,
|
|
|
|
| 83 |
file_type: req.file.mimetype,
|
| 84 |
uploadTime: Date.now(),
|
| 85 |
file_url: `${req.protocol}://${req.get("host")}/files/${filePath}`,
|
| 86 |
+
expires_in: fileData[filePath] ? formatRemainingTime(fileData[filePath].expiredAt) : "Unknown"
|
| 87 |
// Format sesuai sisa waktu
|
| 88 |
});
|
| 89 |
});
|
|
|
|
| 101 |
const paginatedFiles = publicFiles.slice(startIndex, endIndex).map(filename => ({
|
| 102 |
filename,
|
| 103 |
file_url: `${req.protocol}://${req.get("host")}/files/${filename}`,
|
| 104 |
+
expires_in: formatRemainingTime(fileData[filename]?.expiredAt),
|
| 105 |
file_size: fileData[filename]?.fileSize,
|
| 106 |
file_type: fileData[filename]?.file_type,
|
| 107 |
uploadTime: fileData[filename]?.uploadTimeFormat
|
|
|
|
| 137 |
endpoint: "/upload",
|
| 138 |
description: "Upload a file",
|
| 139 |
body: "FormData (key: file)",
|
| 140 |
+
params: "expires_in: number",
|
| 141 |
response: {
|
| 142 |
success: true,
|
| 143 |
+
file_url: "string",
|
| 144 |
+
expires_in: "string"
|
| 145 |
}
|
| 146 |
},
|
| 147 |
list_files: {
|
| 148 |
method: "GET",
|
| 149 |
+
endpoint: "/files/browse",
|
| 150 |
description: "Get all uploaded files",
|
| 151 |
response: {
|
| 152 |
success: true,
|
| 153 |
+
current_page: "number",
|
| 154 |
+
total_pages: "number",
|
| 155 |
+
total_files: "number",
|
| 156 |
+
files: [{
|
| 157 |
+
filename: "string",
|
| 158 |
+
file_url: "string",
|
| 159 |
+
expires_in: "number",
|
| 160 |
+
file_size: "number",
|
| 161 |
+
file_type: "number",
|
| 162 |
+
uploadTime: "number",
|
| 163 |
+
}]
|
| 164 |
}
|
| 165 |
},
|
| 166 |
delete_file: {
|