optimized scripts

pull/19/head
tycrek 4 years ago
parent efe3440903
commit ecdebf73ad
No known key found for this signature in database
GPG Key ID: 25D74F3943625263

@ -23,6 +23,7 @@
- ✔️ Multiple access types
- **[ZWS](https://zws.im)**
- **Mixed-case alphanumeric**
- **Gfycat**
- **Original**
- ❌ Thumbnail support
- ❌ Multiple database types
@ -39,6 +40,7 @@
| ---- | ----------- |
| **[ZWS](https://zws.im)** (Zero-width spaces) | The "fancy" mode. When pasted elsewhere, the URL appears to be *just* your domain name. ![ZWS sample](https://user-images.githubusercontent.com/29926144/113785625-bf43a480-96f4-11eb-8dd7-7f164f33ada2.png "ZWS sample") |
| **Mixed-case alphanumeric** | The "safe" mode. URL's are browser safe as the character set is just letters & numbers. |
| **Gfycat** | Gfycat-style ID's (for example: `https://gfycat.com/unsungdiscretegrub` "unsung discrete grub") |
| **Original** | The "basic" mode. URL matches the same filename as when the file was uploaded. This may be prone to conflicts with files of the same name. |
## Installation
@ -90,7 +92,7 @@ If you need to override a specific part of the config to be different from the g
| Header | Purpose |
| ------ | ------- |
| **`X-Ass-Domain`** | Override the domain returned for the clipboard (useful for multi-domain hosts) |
| **`X-Ass-Access`** | Override the generator used for the resource URI. Must be one of: `original`, `zws`, or `random` ([see above](#access-types)) |
| **`X-Ass-Access`** | Override the generator used for the resource URI. Must be one of: `original`, `zws`, `gfycat`, or `random` ([see above](#access-types)) |
### Fancy embeds

@ -1,19 +1,17 @@
const fs = require('fs-extra');
const adjectiveList = fs.readFileSync("./generators/gfycat/adjectives.txt", "utf-8").split('\n');
const animalsList = fs.readFileSync("./generators/gfycat/animals.txt", "utf-8").split('\n');
const adjectives = fs.readFileSync('./generators/gfycat/adjectives.txt').toString().split('\n');
const animals = fs.readFileSync('./generators/gfycat/animals.txt').toString().split('\n');
const MIN_LENGTH = require('../setup').gfyIdSize;
function genString(adjCount) {
let adjectivesString = "";
for (i = 0; i < adjCount; i++) adjectivesString += genAdjective();
return adjectivesString + genAnimal();
function genString(count = MIN_LENGTH) {
let gfycat = '';
for (i = 0; i < (count < MIN_LENGTH ? MIN_LENGTH : count); i++)
gfycat += getWord(adjectives, '-');
return gfycat.concat(getWord(animals));
};
function genAnimal() {
return animalsList[Math.floor(Math.random()*animalsList.length)];
function getWord(list, delim = '') {
return list[Math.floor(Math.random() * list.length)].concat(delim);
}
function genAdjective() {
return adjectiveList[Math.floor(Math.random()*adjectiveList.length)] + "-";
}
module.exports = (adjectives) => genString(adjectives);
module.exports = ({ gfyLength }) => genString(gfyLength);

@ -1,2 +1,2 @@
const cryptoRandomString = require('crypto-random-string');
module.exports = (length) => cryptoRandomString({ length, type: 'alphanumeric' });
module.exports = ({ length }) => cryptoRandomString({ length, type: 'alphanumeric' });

@ -1,3 +1,3 @@
const { randomBytes } = require('crypto');
const zeroWidthChars = ['\u200B', '\u200C', '\u200D', '\u2060'];
module.exports = (size) => [...randomBytes(size)].map(byte => zeroWidthChars[+byte % zeroWidthChars.length]).join('').slice(1) + zeroWidthChars[0];
module.exports = ({ length }) => [...randomBytes(length)].map(byte => zeroWidthChars[+byte % zeroWidthChars.length]).join('').slice(1) + zeroWidthChars[0];

@ -1,12 +1,3 @@
const { path, log } = require('./utils');
const fs = require('fs-extra');
const prompt = require('prompt');
// Disabled the annoying "prompt: " prefix and removes colours
prompt.message = '';
prompt.colors = false;
prompt.start();
// Default configuration
const config = {
host: '0.0.0.0',
@ -22,6 +13,17 @@ const config = {
saveAsOriginal: true,
};
// If directly called on the command line, run setup script
if (require.main === module) {
const { path, log } = require('./utils');
const fs = require('fs-extra');
const prompt = require('prompt');
// Disabled the annoying "prompt: " prefix and removes colours
prompt.message = '';
prompt.colors = false;
prompt.start();
// Schema for setup prompts
const setupSchema = {
properties: {
@ -62,7 +64,7 @@ const setupSchema = {
required: false
},
gfyIdSize: {
description: 'Adjective count for "gfycat" resource mode',
description: 'Adjective count for "gfycat" Resource ID type',
type: 'integer',
default: config.gfyIdSize,
required: false
@ -125,6 +127,9 @@ function setup() {
}
setup();
}
module.exports = config;
/*{
description: 'Enter your password', // Prompt displayed to the user. If not supplied name will be used.

@ -9,20 +9,21 @@ 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
gfy: 'gfycat' //gfycat-style ID's (example.com/correct-horse-battery-staple)
gfy: 'gfycat' // Gfycat-style ID's (https://gfycat.com/unsungdiscretegrub)
};
const GENERATORS = new Map();
GENERATORS.set(idModes.zws, zwsGen);
GENERATORS.set(idModes.r, randomGen);
GENERATORS.set(idModes.gfy, gfyGen);
module.exports = {
log: console.log,
path: (...paths) => Path.join(__dirname, ...paths),
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, gfyLength, originalName) =>
(mode == idModes.zws) ? zwsGen(lenth)
: (mode == idModes.r) ? randomGen(lenth)
: (mode == idModes.gfy) ? gfyGen(gfyLength)
: originalName,
generateId: (mode, length, gfyLength, originalName) => GENERATORS.has(mode) ? GENERATORS.get(mode)({ length, gfyLength }) : originalName,
formatBytes: (bytes, decimals = 2) => {
if (bytes === 0) return '0 Bytes';
let sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
@ -32,7 +33,8 @@ module.exports = {
randomHexColour: () => { // From: https://www.geeksforgeeks.org/javascript-generate-random-hex-codes-color/
let letters = "0123456789ABCDEF";
let colour = '#';
for (var i = 0; i < 6; i++) colour += letters[(Math.floor(Math.random() * 16))];
for (var i = 0; i < 6; i++)
colour += letters[(Math.floor(Math.random() * 16))];
return colour;
}
}

Loading…
Cancel
Save