Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions get/src/codes.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { getOrcicornShiftCodes } from './source/orcicorn';
import { getFextralifeShiftCodes } from './source/fextralife';
import { getCodeVaultShiftCodes } from './source/codevault';

export async function * getShiftCodes() {
yield * getFextralifeShiftCodes();
yield * getOrcicornShiftCodes();
yield * getCodeVaultShiftCodes();
}
26 changes: 26 additions & 0 deletions get/src/source/codevault.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { ShiftCode } from '../types';

import { parseDate } from '../utils/parseDate';

const BL4_SHIFT_CODES_URL = 'https://code-vault.celo.workers.dev/api/codes';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't think of a good domain so just using the bare cf workers domain. Didn't want to spend the $80 on a .gg 🤣


export async function* getCodeVaultBL4ShiftCodes(): AsyncGenerator<ShiftCode> {
const response = await fetch(BL4_SHIFT_CODES_URL);
const json = (await response.json()) as {
data: { code: string; created_at: string }[];
};

for (const entry of json.data) {
yield {
code: entry.code,
game: 'Borderlands 4',
platform: 'Universal',
reward: 'Unknown',
created: parseDate(entry.created_at),
};
}
}

export async function* getCodeVaultShiftCodes(): AsyncGenerator<ShiftCode> {
yield* getCodeVaultBL4ShiftCodes();
}
7 changes: 1 addition & 6 deletions get/src/source/orcicorn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,10 @@ const Pick = require('stream-json/filters/Pick');
const {streamValues} = require('stream-json/streamers/StreamValues');

import { ShiftCode } from '../types';
import { parseDate } from '../utils/parseDate';

const SHIFT_CODES_URL = 'https://shift.orcicorn.com/shift-code/index.json';

function parseDate(str: string) {
const date = new Date(str);
if (isNaN(date.valueOf())) return undefined;
return date;
}

export async function * getOrcicornShiftCodes(): AsyncGenerator<ShiftCode> {
const response = await fetch(SHIFT_CODES_URL);

Expand Down
5 changes: 5 additions & 0 deletions get/src/utils/parseDate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export function parseDate(str: string) {
const date = new Date(str);
if (isNaN(date.valueOf())) return undefined;
return date;
}