mirror of
https://github.com/BobbyWibowo/lolisafe.git
synced 2025-01-19 01:31:34 +00:00
feat: Constants
This commit is contained in:
parent
cd2baba0d6
commit
ec0e51a7b8
7
controllers/utils/Constants.js
Normal file
7
controllers/utils/Constants.js
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
const self = {
|
||||||
|
IMAGE_EXTS: ['.gif', '.jpeg', '.jpg', '.png', '.svg', '.tif', '.tiff', '.webp'],
|
||||||
|
VIDEO_EXTS: ['.3g2', '.3gp', '.asf', '.avchd', '.avi', '.divx', '.evo', '.flv', '.h264', '.h265', '.hevc', '.m2p', '.m2ts', '.m4v', '.mk3d', '.mkv', '.mov', '.mp4', '.mpeg', '.mpg', '.mxf', '.ogg', '.ogv', '.ps', '.qt', '.rmvb', '.ts', '.vob', '.webm', '.wmv'],
|
||||||
|
AUDIO_EXTS: ['.flac', '.mp3', '.wav', '.wma']
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = self
|
@ -11,6 +11,7 @@ const sharp = require('sharp')
|
|||||||
const si = require('systeminformation')
|
const si = require('systeminformation')
|
||||||
const paths = require('./pathsController')
|
const paths = require('./pathsController')
|
||||||
const perms = require('./permissionController')
|
const perms = require('./permissionController')
|
||||||
|
const Constants = require('./utils/Constants')
|
||||||
const ClientError = require('./utils/ClientError')
|
const ClientError = require('./utils/ClientError')
|
||||||
const ServerError = require('./utils/ServerError')
|
const ServerError = require('./utils/ServerError')
|
||||||
const SimpleDataStore = require('./utils/SimpleDataStore')
|
const SimpleDataStore = require('./utils/SimpleDataStore')
|
||||||
@ -38,10 +39,6 @@ const self = {
|
|||||||
|
|
||||||
idMaxTries: config.uploads.maxTries || 1,
|
idMaxTries: config.uploads.maxTries || 1,
|
||||||
|
|
||||||
imageExts: ['.gif', '.jpeg', '.jpg', '.png', '.svg', '.tif', '.tiff', '.webp'],
|
|
||||||
videoExts: ['.3g2', '.3gp', '.asf', '.avchd', '.avi', '.divx', '.evo', '.flv', '.h264', '.h265', '.hevc', '.m2p', '.m2ts', '.m4v', '.mk3d', '.mkv', '.mov', '.mp4', '.mpeg', '.mpg', '.mxf', '.ogg', '.ogv', '.ps', '.qt', '.rmvb', '.ts', '.vob', '.webm', '.wmv'],
|
|
||||||
audioExts: ['.flac', '.mp3', '.wav', '.wma'],
|
|
||||||
|
|
||||||
stripTagsBlacklistedExts: Array.isArray(config.uploads.stripTags.blacklistExtensions)
|
stripTagsBlacklistedExts: Array.isArray(config.uploads.stripTags.blacklistExtensions)
|
||||||
? config.uploads.stripTags.blacklistExtensions
|
? config.uploads.stripTags.blacklistExtensions
|
||||||
: [],
|
: [],
|
||||||
@ -290,8 +287,8 @@ const cloudflarePurgeCacheQueue = cloudflareAuth && fastq.promise(async chunk =>
|
|||||||
|
|
||||||
self.mayGenerateThumb = extname => {
|
self.mayGenerateThumb = extname => {
|
||||||
extname = extname.toLowerCase()
|
extname = extname.toLowerCase()
|
||||||
return (config.uploads.generateThumbs.image && self.imageExts.includes(extname)) ||
|
return (config.uploads.generateThumbs.image && Constants.IMAGE_EXTS.includes(extname)) ||
|
||||||
(config.uploads.generateThumbs.video && self.videoExts.includes(extname))
|
(config.uploads.generateThumbs.video && Constants.VIDEO_EXTS.includes(extname))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Expand if necessary (should be case-insensitive)
|
// Expand if necessary (should be case-insensitive)
|
||||||
@ -455,7 +452,7 @@ self.generateThumbs = async (name, extname, force) => {
|
|||||||
const input = path.join(paths.uploads, name)
|
const input = path.join(paths.uploads, name)
|
||||||
|
|
||||||
// If image extension
|
// If image extension
|
||||||
if (self.imageExts.includes(extname)) {
|
if (Constants.IMAGE_EXTS.includes(extname)) {
|
||||||
const resizeOptions = {
|
const resizeOptions = {
|
||||||
width: self.thumbsSize,
|
width: self.thumbsSize,
|
||||||
height: self.thumbsSize,
|
height: self.thumbsSize,
|
||||||
@ -489,7 +486,7 @@ self.generateThumbs = async (name, extname, force) => {
|
|||||||
})
|
})
|
||||||
.toFile(thumbname)
|
.toFile(thumbname)
|
||||||
}
|
}
|
||||||
} else if (self.videoExts.includes(extname)) {
|
} else if (Constants.VIDEO_EXTS.includes(extname)) {
|
||||||
const metadata = await self.ffprobe(input)
|
const metadata = await self.ffprobe(input)
|
||||||
|
|
||||||
const duration = parseInt(metadata.format.duration)
|
const duration = parseInt(metadata.format.duration)
|
||||||
@ -556,13 +553,13 @@ self.stripTags = async (name, extname) => {
|
|||||||
let isError
|
let isError
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (self.imageExts.includes(extname)) {
|
if (Constants.IMAGE_EXTS.includes(extname)) {
|
||||||
const tmpName = `tmp-${name}`
|
const tmpName = `tmp-${name}`
|
||||||
tmpPath = path.join(paths.uploads, tmpName)
|
tmpPath = path.join(paths.uploads, tmpName)
|
||||||
await jetpack.renameAsync(fullPath, tmpName)
|
await jetpack.renameAsync(fullPath, tmpName)
|
||||||
await sharp(tmpPath)
|
await sharp(tmpPath)
|
||||||
.toFile(fullPath)
|
.toFile(fullPath)
|
||||||
} else if (config.uploads.stripTags.video && self.videoExts.includes(extname)) {
|
} else if (config.uploads.stripTags.video && Constants.VIDEO_EXTS.includes(extname)) {
|
||||||
const tmpName = `tmp-${name}`
|
const tmpName = `tmp-${name}`
|
||||||
tmpPath = path.join(paths.uploads, tmpName)
|
tmpPath = path.join(paths.uploads, tmpName)
|
||||||
await jetpack.renameAsync(fullPath, tmpName)
|
await jetpack.renameAsync(fullPath, tmpName)
|
||||||
@ -605,7 +602,7 @@ self.unlinkFile = async (filename, predb) => {
|
|||||||
const identifier = filename.split('.')[0]
|
const identifier = filename.split('.')[0]
|
||||||
const extname = self.extname(filename, true)
|
const extname = self.extname(filename, true)
|
||||||
|
|
||||||
if (self.imageExts.includes(extname) || self.videoExts.includes(extname)) {
|
if (Constants.IMAGE_EXTS.includes(extname) || Constants.VIDEO_EXTS.includes(extname)) {
|
||||||
await jetpack.removeAsync(path.join(paths.thumbs, `${identifier}.png`))
|
await jetpack.removeAsync(path.join(paths.thumbs, `${identifier}.png`))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,12 +2,13 @@ const jetpack = require('fs-jetpack')
|
|||||||
const path = require('path')
|
const path = require('path')
|
||||||
const paths = require('./../controllers/pathsController')
|
const paths = require('./../controllers/pathsController')
|
||||||
const utils = require('./../controllers/utilsController')
|
const utils = require('./../controllers/utilsController')
|
||||||
|
const Constants = require('./../controllers/utils/Constants')
|
||||||
|
|
||||||
const self = {
|
const self = {
|
||||||
mode: null,
|
mode: null,
|
||||||
mayGenerateThumb: extname => {
|
mayGenerateThumb: extname => {
|
||||||
return ([1, 3].includes(self.mode) && utils.imageExts.includes(extname)) ||
|
return ([1, 3].includes(self.mode) && Constants.IMAGE_EXTS.includes(extname)) ||
|
||||||
([2, 3].includes(self.mode) && utils.videoExts.includes(extname))
|
([2, 3].includes(self.mode) && Constants.VIDEO_EXTS.includes(extname))
|
||||||
},
|
},
|
||||||
getFiles: async directory => {
|
getFiles: async directory => {
|
||||||
const names = await jetpack.listAsync(directory)
|
const names = await jetpack.listAsync(directory)
|
||||||
|
Loading…
Reference in New Issue
Block a user