mirror of
https://github.com/Drop-OSS/drop.git
synced 2026-07-25 09:14:54 +10:00
Depot API & v4 (#298)
* feat: nginx + torrential basics & services system * fix: lint + i18n * fix: update torrential to remove openssl * feat: add torrential to Docker build * feat: move to self hosted runner * fix: move off self-hosted runner * fix: update nginx.conf * feat: torrential cache invalidation * fix: update torrential for cache invalidation * feat: integrity check task * fix: lint * feat: move to version ids * fix: client fixes and client-side checks * feat: new depot apis and version id fixes * feat: update torrential * feat: droplet bump and remove unsafe update functions * fix: lint * feat: v4 featureset: emulators, multi-launch commands * fix: lint * fix: mobile ui for game editor * feat: launch options * fix: lint * fix: remove axios, use $fetch * feat: metadata and task api improvements * feat: task actions * fix: slight styling issue * feat: fix style and lints * feat: totp backend routes * feat: oidc groups * fix: update drop-base * feat: creation of passkeys & totp * feat: totp signin * feat: webauthn mfa/signin * feat: launch selecting ui * fix: manually running tasks * feat: update add company game modal to use new SelectorGame * feat: executor selector * fix(docker): update rust to rust nightly for torrential build (#305) * feat: new version ui * feat: move package lookup to build time to allow for deno dev * fix: lint * feat: localisation cleanup * feat: apply localisation cleanup * feat: potential i18n refactor logic * feat: remove args from commands * fix: lint * fix: lockfile --------- Co-authored-by: Aden Lindsay <140392385+AdenMGB@users.noreply.github.com>
This commit is contained in:
@@ -9,12 +9,11 @@ import type {
|
||||
_FetchCompanyMetadataParams,
|
||||
CompanyMetadata,
|
||||
} from "./types";
|
||||
import type { AxiosRequestConfig } from "axios";
|
||||
import axios from "axios";
|
||||
import { DateTime } from "luxon";
|
||||
import * as jdenticon from "jdenticon";
|
||||
import type { TaskRunContext } from "../tasks";
|
||||
import { logger } from "~/server/internal/logging";
|
||||
import type { NitroFetchOptions, NitroFetchRequest } from "nitropack";
|
||||
|
||||
type IGDBID = number;
|
||||
|
||||
@@ -171,20 +170,16 @@ export class IGDBProvider implements MetadataProvider {
|
||||
grant_type: "client_credentials",
|
||||
});
|
||||
|
||||
const response = await axios.request<TwitchAuthResponse>({
|
||||
url: `https://id.twitch.tv/oauth2/token?${params.toString()}`,
|
||||
baseURL: "",
|
||||
method: "POST",
|
||||
});
|
||||
const response = await $fetch<TwitchAuthResponse>(
|
||||
`https://id.twitch.tv/oauth2/token?${params.toString()}`,
|
||||
{
|
||||
method: "POST",
|
||||
},
|
||||
);
|
||||
|
||||
if (response.status !== 200)
|
||||
throw new Error(
|
||||
`Error in IGDB \nStatus Code: ${response.status}\n${response.data}`,
|
||||
);
|
||||
|
||||
this.accessToken = response.data.access_token;
|
||||
this.accessToken = response.access_token;
|
||||
this.accessTokenExpiry = DateTime.now().plus({
|
||||
seconds: response.data.expires_in,
|
||||
seconds: response.expires_in,
|
||||
});
|
||||
|
||||
logger.info("IGDB done authorizing with twitch");
|
||||
@@ -202,7 +197,7 @@ export class IGDBProvider implements MetadataProvider {
|
||||
private async request<T extends object>(
|
||||
resource: string,
|
||||
body: string,
|
||||
options?: AxiosRequestConfig,
|
||||
options?: NitroFetchOptions<NitroFetchRequest, "post">,
|
||||
) {
|
||||
await this.refreshCredentials();
|
||||
|
||||
@@ -214,11 +209,10 @@ export class IGDBProvider implements MetadataProvider {
|
||||
|
||||
const finalURL = `https://api.igdb.com/v4/${resource}`;
|
||||
|
||||
const overlay: AxiosRequestConfig = {
|
||||
url: finalURL,
|
||||
const overlay: NitroFetchOptions<NitroFetchRequest, "post"> = {
|
||||
baseURL: "",
|
||||
method: "POST",
|
||||
data: body,
|
||||
body,
|
||||
headers: {
|
||||
Accept: "application/json",
|
||||
"Client-ID": this.clientId,
|
||||
@@ -226,24 +220,13 @@ export class IGDBProvider implements MetadataProvider {
|
||||
"content-type": "text/plain",
|
||||
},
|
||||
};
|
||||
const response = await axios.request<T[] | IGDBErrorResponse[]>(
|
||||
const response = await $fetch<T[] | IGDBErrorResponse[]>(
|
||||
finalURL,
|
||||
Object.assign({}, options, overlay),
|
||||
);
|
||||
|
||||
if (response.status !== 200) {
|
||||
let cause = "";
|
||||
|
||||
response.data.forEach((item) => {
|
||||
if ("cause" in item) cause = item.cause;
|
||||
});
|
||||
|
||||
throw new Error(
|
||||
`Error in igdb \nStatus Code: ${response.status} \nCause: ${cause}`,
|
||||
);
|
||||
}
|
||||
|
||||
// should not have an error object if the status code is 200
|
||||
return <T[]>response.data;
|
||||
return <T[]>response;
|
||||
}
|
||||
|
||||
private async _getMediaInternal(
|
||||
@@ -356,7 +339,7 @@ export class IGDBProvider implements MetadataProvider {
|
||||
return results;
|
||||
}
|
||||
async fetchGame(
|
||||
{ id, publisher, developer, createObject }: _FetchGameMetadataParams,
|
||||
{ id, company, createObject }: _FetchGameMetadataParams,
|
||||
context?: TaskRunContext,
|
||||
): Promise<GameMetadata> {
|
||||
const body = `where id = ${id}; fields *;`;
|
||||
@@ -416,34 +399,28 @@ export class IGDBProvider implements MetadataProvider {
|
||||
{ name: string } & IGDBItem
|
||||
>("companies", `where id = ${foundInvolved.company}; fields name;`);
|
||||
|
||||
for (const company of findCompanyResponse) {
|
||||
for (const companyData of findCompanyResponse) {
|
||||
context?.logger.info(
|
||||
`Found involved company "${company.name}" as: ${foundInvolved.developer ? "developer, " : ""}${foundInvolved.publisher ? "publisher" : ""}`,
|
||||
);
|
||||
|
||||
const res = await company(companyData.name);
|
||||
if (res === undefined) {
|
||||
context?.logger.warn(
|
||||
`Failed to import company "${companyData.name}"`,
|
||||
);
|
||||
continue;
|
||||
}
|
||||
|
||||
// if company was a dev or publisher
|
||||
// CANNOT use else since a company can be both
|
||||
if (foundInvolved.developer) {
|
||||
const res = await developer(company.name);
|
||||
if (res === undefined) {
|
||||
context?.logger.warn(
|
||||
`Failed to import developer "${company.name}"`,
|
||||
);
|
||||
continue;
|
||||
}
|
||||
context?.logger.info(`Imported developer "${company.name}"`);
|
||||
context?.logger.info(`Imported developer "${companyData.name}"`);
|
||||
developers.push(res);
|
||||
}
|
||||
|
||||
if (foundInvolved.publisher) {
|
||||
const res = await publisher(company.name);
|
||||
if (res === undefined) {
|
||||
context?.logger.warn(
|
||||
`Failed to import publisher "${company.name}"`,
|
||||
);
|
||||
continue;
|
||||
}
|
||||
context?.logger.info(`Imported publisher "${company.name}"`);
|
||||
context?.logger.info(`Imported publisher "${companyData.name}"`);
|
||||
publishers.push(res);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user