🕓 feat: added Timestamp generator

pull/171/head
tycrek 2 years ago
parent c4aae93ebb
commit 90466f6104
No known key found for this signature in database
GPG Key ID: FF8A54DCE404885A

4
.github/README.md vendored

@ -58,6 +58,7 @@ ass was designed with developers in mind. If you are a developer & want somethin
- Mixed-case alphanumeric
- Gfycat
- Original
- Timestamp
#### For hosts & developers
@ -102,6 +103,7 @@ ass was designed with developers in mind. If you are a developer & want somethin
| **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://example.com/unsung-discrete-grub`). Thanks to [Gfycat] for the wordlists |
| **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. |
| **Timestamp** | The quick but dirty mode. URL is a timestamp of when the file was uploaded, in milliseconds. This is the most unique mode, but also potentially the longest (Gfycat could be longer, easily). **Keep in mind this is vulnerable to iteration attacks** |
[ZWS sample]: https://user-images.githubusercontent.com/29926144/113785625-bf43a480-96f4-11eb-8dd7-7f164f33ada2.png
[Gfycat]: https://gfycat.com
@ -235,7 +237,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 URL. Must be one of: `original`, `zws`, `gfycat`, or `random` ([see above](#access-types)) |
| **`X-Ass-Access`** | Override the generator used for the resource URL. Must be one of: `original`, `zws`, `gfycat`, `random`, or `timestamp` ([see above](#access-types)) |
| **`X-Ass-Gfycat`** | Override the length of Gfycat ID's. Defaults to `2` |
| **`X-Ass-Timeoffset`** | Override the timestamp offset. Defaults to `UTC+0` |

@ -0,0 +1,3 @@
export default () => {
return `${Date.now()}`;
};

@ -127,12 +127,12 @@ function doSetup() {
required: false
},
resourceIdType: {
description: 'URL type (can be one of: zws, random, gfycat, original)',
description: 'URL type (can be one of: zws, random, gfycat, original, timestamp)',
type: 'string',
default: config.resourceIdType,
require: false,
pattern: /(original|zws|random|gfycat)/gi, // skipcq: JS-0113
message: 'Must be one of: zws, random, gfycat, original'
pattern: /(original|zws|random|gfycat|timestamp)/gi, // skipcq: JS-0113
message: 'Must be one of: zws, random, gfycat, original, timestamp'
},
spaceReplace: {
description: 'Character to replace spaces in filenames with (must be a hyphen -, underscore _, or use ! to remove spaces)',

@ -8,6 +8,7 @@ import token from './generators/token';
import zwsGen from './generators/zws';
import randomGen from './generators/random';
import gfyGen from './generators/gfycat';
import tsGen from './generators/timestamp';
import logger from './logger';
import { Request } from 'express';
const { HTTP, HTTPS, KILOBYTES } = require('../MagicNumbers.json');
@ -79,12 +80,14 @@ 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 (https://gfycat.com/unsungdiscretegrub)
gfy: 'gfycat', // Gfycat-style ID's (https://gfycat.com/unsungdiscretegrub)
ts: 'timestamp', // Timestamp-based ID's
};
const GENERATORS = new Map();
GENERATORS.set(idModes.zws, zwsGen);
GENERATORS.set(idModes.r, randomGen);
GENERATORS.set(idModes.gfy, gfyGen);
GENERATORS.set(idModes.ts, tsGen);
export function generateId(mode: string, length: number, gfyLength: number, originalName: string) {
return (GENERATORS.has(mode) ? GENERATORS.get(mode)({ length, gfyLength }) : originalName);
}

Loading…
Cancel
Save