-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
114,606 additions
and
19,101 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
type Options = { | ||
background?: string | ||
color?: string | ||
exclude_repo?: string | ||
hide?: string | ||
include_all_commits?: string | ||
pixelate_avatar?: string | ||
screen_effect?: string | ||
show?: string | ||
username?: string | ||
theme?: string | ||
avatar_border?: string | ||
dithering?: string | ||
filename: string | ||
} | ||
|
||
export function parseOutputs(outputs: string[]): Array<Options | null> { | ||
return outputs.map(parseOutput) | ||
} | ||
|
||
function parseOutput(output: string): Options | null { | ||
const m = output.trim().match(/^(.+(\.png|))(\?(.*))$/) | ||
|
||
if (!m) return null | ||
|
||
const [, _filename, , query] = m | ||
const filename = _filename.endsWith('.png') ? _filename : `${_filename}.png` | ||
const sp = new URLSearchParams(query || '') | ||
|
||
const { | ||
background, | ||
color, | ||
exclude_repo, | ||
hide = '', | ||
include_all_commits, | ||
pixelate_avatar, | ||
screen_effect, | ||
show, | ||
username, | ||
theme, | ||
avatar_border, | ||
dithering | ||
} = Object.fromEntries(sp) | ||
|
||
console.log(filename, query, { | ||
background, | ||
color, | ||
exclude_repo, | ||
hide, | ||
include_all_commits, | ||
pixelate_avatar, | ||
screen_effect, | ||
show, | ||
username, | ||
theme, | ||
avatar_border, | ||
dithering | ||
}) | ||
|
||
return { | ||
background, | ||
color, | ||
exclude_repo, | ||
hide, | ||
include_all_commits, | ||
pixelate_avatar, | ||
screen_effect, | ||
show, | ||
username, | ||
theme, | ||
avatar_border, | ||
dithering, | ||
filename | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import { isString, objectOf, optional } from 'ts-known' | ||
|
||
export const hasMessage = objectOf({ | ||
message: isString | ||
}) | ||
|
||
export const isPATError = objectOf({ | ||
response: optional( | ||
objectOf({ | ||
data: optional( | ||
objectOf({ | ||
message: optional(isString) | ||
}) | ||
) | ||
}) | ||
) | ||
}) | ||
|
||
const ONE_MINUTE = 60 | ||
const FIVE_MINUTES = 300 | ||
const TEN_MINUTES = 600 | ||
const FIFTEEN_MINUTES = 900 | ||
const THIRTY_MINUTES = 1800 | ||
const TWO_HOURS = 7200 | ||
const FOUR_HOURS = 14400 | ||
const SIX_HOURS = 21600 | ||
const EIGHT_HOURS = 28800 | ||
const ONE_DAY = 86400 | ||
|
||
export const CONSTANTS = { | ||
ONE_MINUTE, | ||
FIVE_MINUTES, | ||
TEN_MINUTES, | ||
FIFTEEN_MINUTES, | ||
THIRTY_MINUTES, | ||
TWO_HOURS, | ||
FOUR_HOURS, | ||
SIX_HOURS, | ||
EIGHT_HOURS, | ||
ONE_DAY, | ||
CARD_CACHE_SECONDS: SIX_HOURS, | ||
ERROR_CACHE_SECONDS: TEN_MINUTES | ||
} | ||
|
||
export function dateDiff(d1: number | string | Date, d2: number | string | Date) { | ||
const date1 = new Date(d1) | ||
const date2 = new Date(d2) | ||
const diff = date1.getTime() - date2.getTime() | ||
|
||
return Math.round(diff / (1000 * 60)) | ||
} | ||
|
||
export function parseArray(str: string | string[] | undefined): string[] { | ||
if (Array.isArray(str)) { | ||
return str | ||
} | ||
|
||
if (!str) { | ||
return [] | ||
} | ||
|
||
return str.split(',') | ||
} | ||
|
||
export function parseBoolean(value: string | string[] | undefined): boolean | undefined { | ||
if (!isString(value)) { | ||
return undefined | ||
} | ||
|
||
if (value.toLowerCase() === 'true') { | ||
return true | ||
} else if (value.toLowerCase() === 'false') { | ||
return false | ||
} | ||
} | ||
|
||
export function parseString(value: string | string[] | undefined): string | undefined { | ||
return isString(value) ? value : undefined | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.