diff options
author | Vijay A <vraravam@users.noreply.github.com> | 2022-05-14 21:46:47 -0500 |
---|---|---|
committer | Vijay Aravamudhan <vraravam@users.noreply.github.com> | 2022-05-15 15:13:19 -0500 |
commit | b153a938645a0c2193a20967325ca855ab671073 (patch) | |
tree | dd126334c16ea46136648147edde0e8125137947 /src/internal-server/app/ImageHelper.js | |
parent | Upgrade 'pnpm' to '7.1.0'; pull in latst version of 'recipes' [skip ci] (diff) | |
download | ferdium-app-b153a938645a0c2193a20967325ca855ab671073.tar.gz ferdium-app-b153a938645a0c2193a20967325ca855ab671073.tar.zst ferdium-app-b153a938645a0c2193a20967325ca855ab671073.zip |
Extracted ImageHelper and ImageController from ServiceController for reuse
Diffstat (limited to 'src/internal-server/app/ImageHelper.js')
-rw-r--r-- | src/internal-server/app/ImageHelper.js | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/internal-server/app/ImageHelper.js b/src/internal-server/app/ImageHelper.js new file mode 100644 index 000000000..b399d08c4 --- /dev/null +++ b/src/internal-server/app/ImageHelper.js | |||
@@ -0,0 +1,24 @@ | |||
1 | const Env = use('Env'); | ||
2 | |||
3 | const { v4: uuid } = require('uuid'); | ||
4 | |||
5 | const path = require('path'); | ||
6 | const fs = require('fs-extra'); | ||
7 | |||
8 | module.exports = async (icon) => { | ||
9 | const iconsPath = path.join(Env.get('USER_PATH'), 'icons'); | ||
10 | await fs.ensureDir(iconsPath); | ||
11 | |||
12 | // Generate new icon ID | ||
13 | let iconId; | ||
14 | do { | ||
15 | iconId = uuid() + uuid(); | ||
16 | } while (fs.existsSync(path.join(iconsPath, iconId))); | ||
17 | iconId = `${iconId}.${icon.extname}`; | ||
18 | |||
19 | await icon.move(iconsPath, { | ||
20 | name: iconId, | ||
21 | overwrite: true, | ||
22 | }); | ||
23 | return !icon.moved() ? '-1' : iconId; | ||
24 | }; | ||