Skip to content

Commit

Permalink
Misc#signURL - CDN URLSignature
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
pakkographic committed May 10, 2024
1 parent d01e1fe commit f948a27
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/rest/endpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`;
23 changes: 23 additions & 0 deletions lib/routes/Misc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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<POSTURLSignatureResponse> {
return this.#manager.authRequest<POSTURLSignatureResponse>({
method: "POST",
path: endpoints.URL_SIGNATURES(),
json: options
});
}
}

0 comments on commit f948a27

Please sign in to comment.