diff options
| author | syuilo <syuilotan@yahoo.co.jp> | 2019-02-06 13:56:21 +0900 |
|---|---|---|
| committer | syuilo <syuilotan@yahoo.co.jp> | 2019-02-06 13:56:21 +0900 |
| commit | 3b5b3cf5212cfa6e34818f370ae5a80f869d56bc (patch) | |
| tree | ccc2398fdf17beec71e8ce7be031f5d09bb73f0e /src | |
| parent | Improve queue configuration (diff) | |
| parent | New Crowdin translations (#4147) (diff) | |
| download | sharkey-3b5b3cf5212cfa6e34818f370ae5a80f869d56bc.tar.gz sharkey-3b5b3cf5212cfa6e34818f370ae5a80f869d56bc.tar.bz2 sharkey-3b5b3cf5212cfa6e34818f370ae5a80f869d56bc.zip | |
Merge branches 'develop' and 'develop' of https://github.com/syuilo/misskey into develop
Diffstat (limited to 'src')
| -rw-r--r-- | src/config/load.ts | 11 | ||||
| -rw-r--r-- | src/misc/logger.ts | 2 | ||||
| -rw-r--r-- | src/prelude/maybe.ts | 20 |
3 files changed, 30 insertions, 3 deletions
diff --git a/src/config/load.ts b/src/config/load.ts index fc3e699199..5bb01f3d41 100644 --- a/src/config/load.ts +++ b/src/config/load.ts @@ -47,14 +47,21 @@ export default function load() { return Object.assign(config, mixin); } -function validateUrl(url: string) { +function tryCreateUrl(url: string) { try { return new URL(url); } catch (e) { - throw `url="${url}" is not a valid URL`; + throw `url="${url}" is not a valid URL.`; } } +function validateUrl(url: string) { + const result = tryCreateUrl(url); + if (result.pathname.replace('/', '').length) throw `url="${url}" is not a valid URL, has a pathname.`; + if (!url.includes(result.host)) throw `url="${url}" is not a valid URL, has an invalid hostname.`; + return result; +} + function normalizeUrl(url: string) { return url.endsWith('/') ? url.substr(0, url.length - 1) : url; } diff --git a/src/misc/logger.ts b/src/misc/logger.ts index 609c255849..7b669c3bb1 100644 --- a/src/misc/logger.ts +++ b/src/misc/logger.ts @@ -45,7 +45,7 @@ export default class Logger { this.log(important ? chalk.bgGreen.white('DONE') : chalk.green('DONE'), chalk.green(message), important); } - public debug(message: string, important = false): void { // デバッグ用に使う(開発者にとっては必要だが利用者にとっては不要な情報) + public debug(message: string, important = false): void { // デバッグ用に使う(開発者に必要だが利用者に不要な情報) if (process.env.NODE_ENV != 'production' || program.verbose) { this.log(chalk.gray('VERB'), chalk.gray(message), important); } diff --git a/src/prelude/maybe.ts b/src/prelude/maybe.ts new file mode 100644 index 0000000000..f9ac95c0b5 --- /dev/null +++ b/src/prelude/maybe.ts @@ -0,0 +1,20 @@ +export interface Maybe<T> { + isJust(): this is Just<T>; +} + +export type Just<T> = Maybe<T> & { + get(): T +}; + +export function just<T>(value: T): Just<T> { + return { + isJust: () => true, + get: () => value + }; +} + +export function nothing<T>(): Maybe<T> { + return { + isJust: () => false, + }; +} |