diff options
| author | Adam Soltys <[email protected]> | 2023-01-06 21:11:39 -0800 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2023-01-06 21:11:39 -0800 |
| commit | 34e87ab8192928cb0ec2096caa27f6bcdff686b1 (patch) | |
| tree | 65e8025eeb467fde1fbafddfe1950965b28a3868 /lib/sync.js | |
| parent | b02ba909998a8a61145eaaaadb3beb1845d4a151 (diff) | |
| download | coinos-server-34e87ab8192928cb0ec2096caa27f6bcdff686b1.tar.gz coinos-server-34e87ab8192928cb0ec2096caa27f6bcdff686b1.zip | |
rename images endpoint
Diffstat (limited to 'lib/sync.js')
| -rw-r--r-- | lib/sync.js | 30 |
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({}); +}); |
