aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2023-01-06 21:11:39 -0800
committerAdam Soltys <[email protected]>2023-01-06 21:11:39 -0800
commit34e87ab8192928cb0ec2096caa27f6bcdff686b1 (patch)
tree65e8025eeb467fde1fbafddfe1950965b28a3868 /lib
parentb02ba909998a8a61145eaaaadb3beb1845d4a151 (diff)
downloadcoinos-server-34e87ab8192928cb0ec2096caa27f6bcdff686b1.tar.gz
coinos-server-34e87ab8192928cb0ec2096caa27f6bcdff686b1.zip
rename images endpoint
Diffstat (limited to 'lib')
-rw-r--r--lib/sync.js30
1 files changed, 30 insertions, 0 deletions
diff --git a/lib/sync.js b/lib/sync.js
index 97207752..9e2fc31c 100644
--- a/lib/sync.js
+++ b/lib/sync.js
@@ -13,6 +13,7 @@ import ln from "./ln";
import lnd from "./lnd";
import bc from "./bitcoin";
import lq from "./liquid";
+import { adminAuth } from "$lib/passport";
const init = async () => {
try {
@@ -382,3 +383,32 @@ app.get("/conversions", async (req, res) => {
.filter(c => !payments.includes(c))
);
});
+
+app.post("/renameImages", adminAuth, async (req, res) => {
+ let d = './uploads/';
+ fs.readdir(d, (err, files) => {
+ files.forEach(async file => {
+ try {
+ let m = file.match(/(.*)-profile/);
+
+ let username;
+
+ if (m && m[1]) username = m[1];
+ else m = file.match(/(.*)-banner/);
+ if (m && m[1]) username = m[1];
+
+ console.log(username);
+
+ if (username) {
+ let { uuid } = await db.User.findOne({ where: { username } });
+ fs.rename(d + file, d + uuid + file.replace(username, ""), function(err) {
+ if (err) console.log("ERROR: " + err);
+ });
+ }
+ } catch (e) {
+ console.log(e);
+ }
+ });
+ });
+ res.send({});
+});