Spaces:
Running
Running
first
Browse files- app.js +83 -0
- package-lock.json +15 -1
- package.json +3 -1
app.js
CHANGED
@@ -3,6 +3,9 @@ const cors = require("cors");
|
|
3 |
const multer = require("multer");
|
4 |
const fs = require("fs");
|
5 |
const path = require("path");
|
|
|
|
|
|
|
6 |
|
7 |
const app = express();
|
8 |
const port = process.env.PORT || 7860;
|
@@ -63,6 +66,86 @@ app.delete("/files/:filename", (req, res) => {
|
|
63 |
});
|
64 |
});
|
65 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
66 |
app.listen(port, () => {
|
67 |
console.log("Listening on http://localhost:" + port);
|
68 |
});
|
|
|
3 |
const multer = require("multer");
|
4 |
const fs = require("fs");
|
5 |
const path = require("path");
|
6 |
+
const os = require("os");
|
7 |
+
const { execSync } = require("child_process");
|
8 |
+
|
9 |
|
10 |
const app = express();
|
11 |
const port = process.env.PORT || 7860;
|
|
|
66 |
});
|
67 |
});
|
68 |
|
69 |
+
app.get("/", (req, res) => {
|
70 |
+
res.json({
|
71 |
+
success: true,
|
72 |
+
message: "Welcome to Temporary Cloud File API 🚀",
|
73 |
+
usage: {
|
74 |
+
upload_file: {
|
75 |
+
method: "POST",
|
76 |
+
endpoint: "/upload",
|
77 |
+
description: "Upload a file",
|
78 |
+
body: "FormData (key: file)",
|
79 |
+
response: {
|
80 |
+
success: true,
|
81 |
+
file_url: "http://yourdomain.com/files/filename.ext",
|
82 |
+
expires_in: "24h"
|
83 |
+
}
|
84 |
+
},
|
85 |
+
list_files: {
|
86 |
+
method: "GET",
|
87 |
+
endpoint: "/files",
|
88 |
+
description: "Get all uploaded files",
|
89 |
+
response: {
|
90 |
+
success: true,
|
91 |
+
files: [
|
92 |
+
{
|
93 |
+
filename: "example.txt",
|
94 |
+
file_url: "http://yourdomain.com/files/example.txt"
|
95 |
+
}
|
96 |
+
]
|
97 |
+
}
|
98 |
+
},
|
99 |
+
delete_file: {
|
100 |
+
method: "DELETE",
|
101 |
+
endpoint: "/files/:filename",
|
102 |
+
description: "Delete a file",
|
103 |
+
response: {
|
104 |
+
success: true,
|
105 |
+
message: "File deleted successfully!"
|
106 |
+
}
|
107 |
+
},
|
108 |
+
check_server: {
|
109 |
+
method: "GET",
|
110 |
+
endpoint: "/status",
|
111 |
+
description: "Check server status (RAM, CPU, uptime, etc.)"
|
112 |
+
}
|
113 |
+
},
|
114 |
+
author: "rizxyu",
|
115 |
+
github: "https://github.com/rizxyu"
|
116 |
+
});
|
117 |
+
});
|
118 |
+
|
119 |
+
|
120 |
+
app.get("/status", (req, res) => {
|
121 |
+
const uptime = process.uptime();
|
122 |
+
const memoryUsage = process.memoryUsage();
|
123 |
+
const cpuLoad = os.loadavg();
|
124 |
+
|
125 |
+
let diskUsage = "Not available";
|
126 |
+
try {
|
127 |
+
diskUsage = execSync("df -h / | tail -1 | awk '{print $3 \" used / \" $2 \" total (\" $5 \" used)\"}'").toString().trim();
|
128 |
+
} catch (err) {
|
129 |
+
diskUsage = "Error fetching disk usage";
|
130 |
+
}
|
131 |
+
|
132 |
+
res.json({
|
133 |
+
success: true,
|
134 |
+
server_time: new Date().toISOString(),
|
135 |
+
uptime: `${Math.floor(uptime / 3600)}h ${Math.floor((uptime % 3600) / 60)}m ${Math.floor(uptime % 60)}s`,
|
136 |
+
memory: {
|
137 |
+
total: `${(os.totalmem() / 1024 / 1024).toFixed(2)} MB`,
|
138 |
+
used: `${(memoryUsage.rss / 1024 / 1024).toFixed(2)} MB`
|
139 |
+
},
|
140 |
+
cpu: {
|
141 |
+
cores: os.cpus().length,
|
142 |
+
load_avg: cpuLoad.map(load => load.toFixed(2))
|
143 |
+
},
|
144 |
+
disk: diskUsage,
|
145 |
+
node_version: process.version
|
146 |
+
});
|
147 |
+
});
|
148 |
+
|
149 |
app.listen(port, () => {
|
150 |
console.log("Listening on http://localhost:" + port);
|
151 |
});
|
package-lock.json
CHANGED
@@ -9,9 +9,11 @@
|
|
9 |
"version": "1.0.1",
|
10 |
"license": "MIT",
|
11 |
"dependencies": {
|
|
|
12 |
"cors": "^2.8.5",
|
13 |
"express": "^4.21.2",
|
14 |
-
"multer": "^1.4.5-lts.2"
|
|
|
15 |
}
|
16 |
},
|
17 |
"node_modules/accepts": {
|
@@ -118,6 +120,12 @@
|
|
118 |
"url": "https://github.com/sponsors/ljharb"
|
119 |
}
|
120 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
121 |
"node_modules/concat-stream": {
|
122 |
"version": "1.6.2",
|
123 |
"resolved": "https://registry.npmjs.org/concat-stream/-/concat-stream-1.6.2.tgz",
|
@@ -659,6 +667,12 @@
|
|
659 |
"node": ">= 0.8"
|
660 |
}
|
661 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
662 |
"node_modules/parseurl": {
|
663 |
"version": "1.3.3",
|
664 |
"resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.3.tgz",
|
|
|
9 |
"version": "1.0.1",
|
10 |
"license": "MIT",
|
11 |
"dependencies": {
|
12 |
+
"child_process": "^1.0.2",
|
13 |
"cors": "^2.8.5",
|
14 |
"express": "^4.21.2",
|
15 |
+
"multer": "^1.4.5-lts.2",
|
16 |
+
"os": "^0.1.2"
|
17 |
}
|
18 |
},
|
19 |
"node_modules/accepts": {
|
|
|
120 |
"url": "https://github.com/sponsors/ljharb"
|
121 |
}
|
122 |
},
|
123 |
+
"node_modules/child_process": {
|
124 |
+
"version": "1.0.2",
|
125 |
+
"resolved": "https://registry.npmjs.org/child_process/-/child_process-1.0.2.tgz",
|
126 |
+
"integrity": "sha512-Wmza/JzL0SiWz7kl6MhIKT5ceIlnFPJX+lwUGj7Clhy5MMldsSoJR0+uvRzOS5Kv45Mq7t1PoE8TsOA9bzvb6g==",
|
127 |
+
"license": "ISC"
|
128 |
+
},
|
129 |
"node_modules/concat-stream": {
|
130 |
"version": "1.6.2",
|
131 |
"resolved": "https://registry.npmjs.org/concat-stream/-/concat-stream-1.6.2.tgz",
|
|
|
667 |
"node": ">= 0.8"
|
668 |
}
|
669 |
},
|
670 |
+
"node_modules/os": {
|
671 |
+
"version": "0.1.2",
|
672 |
+
"resolved": "https://registry.npmjs.org/os/-/os-0.1.2.tgz",
|
673 |
+
"integrity": "sha512-ZoXJkvAnljwvc56MbvhtKVWmSkzV712k42Is2mA0+0KTSRakq5XXuXpjZjgAt9ctzl51ojhQWakQQpmOvXWfjQ==",
|
674 |
+
"license": "MIT"
|
675 |
+
},
|
676 |
"node_modules/parseurl": {
|
677 |
"version": "1.3.3",
|
678 |
"resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.3.tgz",
|
package.json
CHANGED
@@ -14,8 +14,10 @@
|
|
14 |
"author": "rizxyu",
|
15 |
"license": "MIT",
|
16 |
"dependencies": {
|
|
|
17 |
"cors": "^2.8.5",
|
18 |
"express": "^4.21.2",
|
19 |
-
"multer": "^1.4.5-lts.2"
|
|
|
20 |
}
|
21 |
}
|
|
|
14 |
"author": "rizxyu",
|
15 |
"license": "MIT",
|
16 |
"dependencies": {
|
17 |
+
"child_process": "^1.0.2",
|
18 |
"cors": "^2.8.5",
|
19 |
"express": "^4.21.2",
|
20 |
+
"multer": "^1.4.5-lts.2",
|
21 |
+
"os": "^0.1.2"
|
22 |
}
|
23 |
}
|