Skip to content

Commit

Permalink
add refresh attachment urls route
Browse files Browse the repository at this point in the history
  • Loading branch information
DonovanDMC committed Apr 19, 2024
1 parent ae2b8fc commit fc9445a
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
17 changes: 17 additions & 0 deletions lib/routes/Miscellaneous.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as Routes from "../util/Routes";
import type RESTManager from "../rest/RESTManager";
import type { RawSticker, RawStickerPack, Sticker, StickerPack } from "../types/guilds";
import type { VoiceRegion } from "../types/voice";
import type { RawRefreshAttachmentURLsResponse, RefreshAttachmentURLsResponse } from "../types/misc";

/** Methods that don't fit anywhere else. Located at {@link Client#rest | Client#rest}{@link RESTManager#misc | .misc}. */
export default class Miscellaneous {
Expand Down Expand Up @@ -53,4 +54,20 @@ export default class Miscellaneous {
path: Routes.VOICE_REGIONS
});
}

/**
* Refresh expired attachment URLs.
* @param urls The CDN urls to refresh.
*/
async refreshAttachmentURLs(urls: Array<string>): Promise<RefreshAttachmentURLsResponse> {
return this.#manager.authRequest<RawRefreshAttachmentURLsResponse>({
method: "POST",
path: Routes.REFRESH_ATTACHMENT_URLS,
json: {
attachment_urls: urls
}
}).then(data => ({
refreshedURLs: data.refreshed_urls
}));
}
}
12 changes: 12 additions & 0 deletions lib/types/misc.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,15 @@ export type WithRequired<T, K extends keyof T> = Omit<T, K> & Required<Pick<T, K
export type Nullable<T> = {
[K in keyof T]: T[K] | null;
};

export interface RawRefreshAttachmentURLsResponse {
refreshed_urls: Array<RefreshedAttachment>;
}
export interface RefreshAttachmentURLsResponse {
refreshedURLs: Array<RefreshedAttachment>;
}

export interface RefreshedAttachment {
original: string;
refreshed: string;
}
1 change: 1 addition & 0 deletions lib/util/Routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,4 @@ export const STICKER_PACKS = "/sticker-packs" as const;
export const INVITE = (code: string) => `/invites/${code}` as const;
export const STAGE_INSTANCES = "/stage-instances" as const;
export const STAGE_INSTANCE = (channelID: string) => `/stage-instances/${channelID}` as const;
export const REFRESH_ATTACHMENT_URLS = "/attachments/refresh-urls" as const;

0 comments on commit fc9445a

Please sign in to comment.