* fix refreshing * woah 50 limit * fixes * Increase delay in GIF picker query dispatch --------- Co-authored-by: thororen <78185467+thororen1234@users.noreply.github.com>
34 lines
962 B
TypeScript
34 lines
962 B
TypeScript
/*
|
|
* Vencord, a Discord client mod
|
|
* Copyright (c) 2024 Vendicated and contributors
|
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
|
*/
|
|
|
|
import { RestAPI } from "@webpack/common";
|
|
|
|
export function isCdnUrlExpired(url: string): boolean {
|
|
try {
|
|
const ex = new URL(url).searchParams.get("ex");
|
|
if (!ex) return false;
|
|
return parseInt(ex, 16) * 1000 < Date.now();
|
|
} catch {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
export async function batchRefreshAttachmentUrls(urls: string[]): Promise<Record<string, string>> {
|
|
try {
|
|
const response = await RestAPI.post({
|
|
url: "/attachments/refresh-urls",
|
|
body: { attachment_urls: urls }
|
|
});
|
|
if (!response.ok) return {};
|
|
const map: Record<string, string> = {};
|
|
for (const { original, refreshed } of response.body.refreshed_urls) {
|
|
map[original] = refreshed;
|
|
}
|
|
return map;
|
|
} catch {
|
|
return {};
|
|
}
|
|
}
|