🕓 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 - Mixed-case alphanumeric
- Gfycat - Gfycat
- Original - Original
- Timestamp
#### For hosts & developers #### 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. | | **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 | | **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. | | **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 [ZWS sample]: https://user-images.githubusercontent.com/29926144/113785625-bf43a480-96f4-11eb-8dd7-7f164f33ada2.png
[Gfycat]: https://gfycat.com [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 | | Header | Purpose |
| ------ | ------- | | ------ | ------- |
| **`X-Ass-Domain`** | Override the domain returned for the clipboard (useful for multi-domain hosts) | | **`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-Gfycat`** | Override the length of Gfycat ID's. Defaults to `2` |
| **`X-Ass-Timeoffset`** | Override the timestamp offset. Defaults to `UTC+0` | | **`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 required: false
}, },
resourceIdType: { 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', type: 'string',
default: config.resourceIdType, default: config.resourceIdType,
require: false, require: false,
pattern: /(original|zws|random|gfycat)/gi, // skipcq: JS-0113 pattern: /(original|zws|random|gfycat|timestamp)/gi, // skipcq: JS-0113
message: 'Must be one of: zws, random, gfycat, original' message: 'Must be one of: zws, random, gfycat, original, timestamp'
}, },
spaceReplace: { spaceReplace: {
description: 'Character to replace spaces in filenames with (must be a hyphen -, underscore _, or use ! to remove spaces)', 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 zwsGen from './generators/zws';
import randomGen from './generators/random'; import randomGen from './generators/random';
import gfyGen from './generators/gfycat'; import gfyGen from './generators/gfycat';
import tsGen from './generators/timestamp';
import logger from './logger'; import logger from './logger';
import { Request } from 'express'; import { Request } from 'express';
const { HTTP, HTTPS, KILOBYTES } = require('../MagicNumbers.json'); const { HTTP, HTTPS, KILOBYTES } = require('../MagicNumbers.json');
@ -79,12 +80,14 @@ const idModes = {
zws: 'zws', // Zero-width spaces (see: https://zws.im/) zws: 'zws', // Zero-width spaces (see: https://zws.im/)
og: 'original', // Use original uploaded filename og: 'original', // Use original uploaded filename
r: 'random', // Use a randomly generated ID with a mixed-case alphanumeric character set 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(); const GENERATORS = new Map();
GENERATORS.set(idModes.zws, zwsGen); GENERATORS.set(idModes.zws, zwsGen);
GENERATORS.set(idModes.r, randomGen); GENERATORS.set(idModes.r, randomGen);
GENERATORS.set(idModes.gfy, gfyGen); GENERATORS.set(idModes.gfy, gfyGen);
GENERATORS.set(idModes.ts, tsGen);
export function generateId(mode: string, length: number, gfyLength: number, originalName: string) { export function generateId(mode: string, length: number, gfyLength: number, originalName: string) {
return (GENERATORS.has(mode) ? GENERATORS.get(mode)({ length, gfyLength }) : originalName); return (GENERATORS.has(mode) ? GENERATORS.get(mode)({ length, gfyLength }) : originalName);
} }

Loading…
Cancel
Save