Gfycat Resource type

pull/16/head
Jacob Herd 3 years ago
parent 31eafd787e
commit 82aaafa990
No known key found for this signature in database
GPG Key ID: A8B5DDE601323A5C

@ -7,7 +7,7 @@ try {
}
// Load the config
const { host, port, domain, useSsl, resourceIdSize, resourceIdType, isProxied, diskFilePath, saveWithDate, saveAsOriginal } = require('./config.json');
const { host, port, domain, useSsl, resourceIdSize, gfyIdSize, resourceIdType, isProxied, diskFilePath, saveWithDate, saveAsOriginal } = require('./config.json');
//#region Imports
const fs = require('fs-extra');
@ -98,7 +98,7 @@ function startup() {
};
// Save the file information
let resourceId = generateId(generator, resourceIdSize, req.file.originalname);
let resourceId = generateId(generator, resourceIdSize, gfyIdSize, req.file.originalname);
data[resourceId.split('.')[0]] = req.file;
saveData(data);

@ -0,0 +1,19 @@
const fs = require('fs-extra');
const adjectiveList = fs.readFileSync("./gfycat/adjectives.txt", "utf-8").split('\n');
const animalsList = fs.readFileSync("./gfycat/animals.txt", "utf-8").split('\n');
function genString(adjCount) {
let adjectivesString = "";
for (i = 0; i < adjCount; i++) adjectivesString += genAdjective();
return adjectivesString + genAnimal();
};
function genAnimal() {
return animalsList[Math.floor(Math.random()*animalsList.length)];
}
function genAdjective() {
return adjectiveList[Math.floor(Math.random()*adjectiveList.length)] + "-";
}
module.exports = (adjectives) => genString(adjectives);

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

@ -15,6 +15,7 @@ const config = {
useSsl: true,
isProxied: true,
resourceIdSize: 12,
gfyIdSize: 2,
resourceIdType: 'zws',
diskFilePath: "uploads/",
saveWithDate: false,
@ -60,14 +61,21 @@ const setupSchema = {
default: config.resourceIdSize,
required: false
},
gfyIdSize: {
description: 'Adjective count for "gfycat" resource mode',
type: 'integer',
default: config.gfyIdSize,
required: false
},
resourceIdType: {
description: 'Resource ID type (determines what kind of URL your uploads are visible at. Can be one of: original, zws, random)',
type: 'string',
default: config.resourceIdType,
require: false,
pattern: /(original|zws|random)/gi,
message: 'Must be one of: original, zws, random'
pattern: /(original|zws|random|gfycat)/gi,
message: 'Must be one of: original, zws, random, gfycat'
},
diskFilePath: {
description: 'Relative path to save uploads to',
type: 'string',

@ -3,12 +3,13 @@ const Path = require('path');
const token = require('./generators/token');
const zwsGen = require('./generators/zws');
const randomGen = require('./generators/random');
const gfyGen = require('./generators/gfycat');
const idModes = {
zws: 'zws', // Zero-width spaces (see: https://zws.im/)
og: 'original', // Use original uploaded filename
r: 'random' // Use a randomly generated ID with a mixed-case alphanumeric character set
// todo: gfycat-style ID's (example.com/correct-horse-battery-staple)
r: 'random', // Use a randomly generated ID with a mixed-case alphanumeric character set
gfy: 'gfycat' //gfycat-style ID's (example.com/correct-horse-battery-staple)
};
module.exports = {
@ -17,10 +18,11 @@ module.exports = {
saveData: (data) => fs.writeJsonSync(Path.join(__dirname, 'data.json'), data, { spaces: 4 }),
verify: (req, tokens) => req.headers.authorization && tokens.includes(req.headers.authorization),
generateToken: () => token(),
generateId: (mode, lenth, originalName) =>
generateId: (mode, lenth, gfyLength, originalName) =>
(mode == idModes.zws) ? zwsGen(lenth)
: (mode == idModes.r) ? randomGen(lenth)
: originalName,
: (mode == idModes.gfy) ? gfyGen(gfyLength)
: originalName,
formatBytes: (bytes, decimals = 2) => {
if (bytes === 0) return '0 Bytes';
let sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];

Loading…
Cancel
Save