Add /arubinosky (3)
This commit is contained in:
@@ -5,3 +5,13 @@ export function tryOneOf<const T>(
|
|||||||
if (consts.includes(value)) return value;
|
if (consts.includes(value)) return value;
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function sample<T>(arr: T[], n: number = arr.length): T[] {
|
||||||
|
if (n > arr.length) return sample(arr, arr.length);
|
||||||
|
const copy = [...arr];
|
||||||
|
for (let i = 0; i < n; i++) {
|
||||||
|
const j = i + Math.floor(Math.random() * (copy.length - i));
|
||||||
|
[copy[i], copy[j]] = [copy[j] as T, copy[i] as T];
|
||||||
|
}
|
||||||
|
return copy.slice(0, n);
|
||||||
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import { RateLimiter } from "sveltekit-rate-limiter/server";
|
|||||||
import { dev } from "$app/environment";
|
import { dev } from "$app/environment";
|
||||||
import { MISSKEY_API_KEY } from "$env/static/private";
|
import { MISSKEY_API_KEY } from "$env/static/private";
|
||||||
import type { InviteListResponse } from "misskey-js/entities.js";
|
import type { InviteListResponse } from "misskey-js/entities.js";
|
||||||
|
import { sample } from "$lib";
|
||||||
|
|
||||||
const limiter = new RateLimiter({
|
const limiter = new RateLimiter({
|
||||||
IP: [10, "d"], // IP address limiter
|
IP: [10, "d"], // IP address limiter
|
||||||
@@ -30,8 +31,7 @@ export async function GET(event: RequestEvent) {
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
const json = await res.json();
|
const json = await res.json();
|
||||||
console.log(json);
|
const invite = sample(json as InviteListResponse).find(
|
||||||
const invite = (json as InviteListResponse).find(
|
|
||||||
(x) => !x.createdBy && !x.usedAt,
|
(x) => !x.createdBy && !x.usedAt,
|
||||||
);
|
);
|
||||||
if (invite) return text(invite.code);
|
if (invite) return text(invite.code);
|
||||||
|
|||||||
Reference in New Issue
Block a user