From f948a2787b506327c26186c4ced81f2cc3585abb Mon Sep 17 00:00:00 2001 From: pakkographic <41129374+pakkographic@users.noreply.github.com> Date: Sat, 11 May 2024 01:21:35 +0200 Subject: [PATCH] Misc#signURL - CDN URLSignature Basic integration of the URL Signature API request into TouchGuild. Note that TouchGuild doesn't provide a built-in handler for CDN assets. This can be done with a 3rd party library, that is whether existing or needs to be created, or implementing your own way to save CDN assets. We do not recommend to use the Guilded CDN in its current state, as it complexifies the simple and efficient infrastructure that was needed for a Guilded Application, making it complex (as you can't save in cloud servers while your app is running, that requires the use of an additional structure, making it harder for small, indie projects to make commercial, or even free applications if not stored locally on a computer). --- lib/rest/endpoints.ts | 2 ++ lib/routes/Misc.ts | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/lib/rest/endpoints.ts b/lib/rest/endpoints.ts index 7f1e399d..92cf11ed 100644 --- a/lib/rest/endpoints.ts +++ b/lib/rest/endpoints.ts @@ -104,3 +104,5 @@ export const GUILD_WEBHOOK = (guildID: string, webhookID: string)=> `/servers/${ export const GUILD_CATEGORY_CREATE = (guildID: string) => `/servers/${guildID}/categories`; export const GUILD_CATEGORY = (guildID: string, categoryID: number) => `/servers/${guildID}/categories/${categoryID}`; + +export const URL_SIGNATURES = () => `/url-signatures`; diff --git a/lib/routes/Misc.ts b/lib/routes/Misc.ts index a61f3ddc..c39213d3 100644 --- a/lib/routes/Misc.ts +++ b/lib/routes/Misc.ts @@ -5,6 +5,7 @@ import { GETGuildMemberSocialsResponse, GETUserResponse, GETUserServersResponse, import { User } from "../structures/User"; import { SocialLink } from "../structures/SocialLink"; import { Guild } from "../structures/Guild"; +import { POSTURLSignatureBody, POSTURLSignatureResponse } from "guildedapi-types.ts/typings/REST/v1/URLSignature"; /** Miscellaneous routes. */ export class Miscellaneous { @@ -76,4 +77,26 @@ export class Miscellaneous { path: endpoints.USER_STATUS(userID) }); } + + /** + * Create a URL Signature from a Guilded CDN URL. (RAW API RESPONSE) + * + * Due to restrictions imposed by the Guilded API CDN, + * you are required to sign the file's CDN URL in order to access its content, + * and have to store it (within 5 minutes as the signed URL will expire) + * appropriately as you can only create a new signed URL of the same file + * each day. + * + * More information about it on the Guilded API Documentation. + * + * Note that TouchGuild doesn't provide a built-in handler for CDN assets. + * @param options Signature options + */ + async signURL(options: POSTURLSignatureBody): Promise { + return this.#manager.authRequest({ + method: "POST", + path: endpoints.URL_SIGNATURES(), + json: options + }); + } }