From 47bc7109765cc607a533a36dc70b3e6e6de0e97f Mon Sep 17 00:00:00 2001 From: Duane Irvin Date: Thu, 7 May 2026 10:42:47 +0200 Subject: [PATCH] Fix auth cache dir --- src/commands/gxgames/auth/index.ts | 4 ++-- src/commands/gxgames/auth/storage.ts | 23 +++++++++++-------- src/commands/gxgames/commands/link-impl.ts | 4 ++-- src/commands/gxgames/commands/meta-impl.ts | 2 +- src/commands/gxgames/commands/publish-impl.ts | 2 +- src/commands/gxgames/commands/upload-impl.ts | 2 +- 6 files changed, 21 insertions(+), 16 deletions(-) diff --git a/src/commands/gxgames/auth/index.ts b/src/commands/gxgames/auth/index.ts index 05d87ff..342082d 100644 --- a/src/commands/gxgames/auth/index.ts +++ b/src/commands/gxgames/auth/index.ts @@ -183,12 +183,12 @@ class Auth { } } -export function createAuthManager(ctx: Context) { +export function createAuthManager(ctx: Context, projectDir?: string) { return new Auth({ fetch: ctx.fetch, http: ctx.http, open: ctx.open, makeTaskLogger: ctx.makeTaskLogger, - storage: new AuthStorage(ctx), + storage: new AuthStorage(ctx, projectDir), }); } diff --git a/src/commands/gxgames/auth/storage.ts b/src/commands/gxgames/auth/storage.ts index d6575cf..59932a0 100644 --- a/src/commands/gxgames/auth/storage.ts +++ b/src/commands/gxgames/auth/storage.ts @@ -30,13 +30,13 @@ const AuthSchema = z.object({ export type GxGamesAuth = z.infer; export class AuthStorage { - constructor(private readonly ctx: Context) {} + constructor( + private readonly ctx: Context, + private readonly projectDir?: string, + ) {} async read(): Promise { - const cache = await Cache.initLazy(this.ctx, { type: "infer" }); - const dir = await cache.getSubDirPath(this.ctx, CACHE_SUBDIR, { - preferShared: true, - }); + const dir = await this.cacheDir(); try { const raw = await this.ctx.fs.readFile( this.ctx.path.join(dir, AUTH_FILENAME), @@ -49,13 +49,18 @@ export class AuthStorage { } async write(auth: GxGamesAuth): Promise { - const cache = await Cache.initLazy(this.ctx, { type: "infer" }); - const dir = await cache.getSubDirPath(this.ctx, CACHE_SUBDIR, { - preferShared: true, - }); + const dir = await this.cacheDir(); await this.ctx.fs.writeFile( this.ctx.path.join(dir, AUTH_FILENAME), JSON.stringify(auth, null, 2), ); } + + private async cacheDir(): Promise { + const cache = await Cache.initLazy(this.ctx, { + type: "infer", + projectDir: this.projectDir, + }); + return cache.getSubDirPath(this.ctx, CACHE_SUBDIR, { preferShared: true }); + } } diff --git a/src/commands/gxgames/commands/link-impl.ts b/src/commands/gxgames/commands/link-impl.ts index b98990b..4308241 100644 --- a/src/commands/gxgames/commands/link-impl.ts +++ b/src/commands/gxgames/commands/link-impl.ts @@ -30,9 +30,10 @@ export default async function ( ): Promise { let studioId = flags.studioid; let gameId = flags.gameid; + const projectDir = project ? this.path.dirname(project) : undefined; if (!studioId || !gameId) { - const api = getApiClient(this, createAuthManager(this)); + const api = getApiClient(this, createAuthManager(this, projectDir)); if (!studioId) { const studiosRes = await api.getUserStudios({ pageSize: 999 }); @@ -99,7 +100,6 @@ export default async function ( } } - const projectDir = project ? this.path.dirname(project) : undefined; await new LinkStorage(this, projectDir).write({ studioId, gameId }); p.log.success(`Linked to studio ${studioId}, game ${gameId}`); } diff --git a/src/commands/gxgames/commands/meta-impl.ts b/src/commands/gxgames/commands/meta-impl.ts index f559310..2801d97 100644 --- a/src/commands/gxgames/commands/meta-impl.ts +++ b/src/commands/gxgames/commands/meta-impl.ts @@ -43,7 +43,7 @@ export default async function ( ): Promise { const projectDir = project ? this.path.dirname(project) : undefined; const link = await new LinkStorage(this, projectDir).read(); - const api = getApiClient(this, createAuthManager(this)); + const api = getApiClient(this, createAuthManager(this, projectDir)); const gameRes = await api.getGameDetails(link.gameId); if (!gameRes.success) { diff --git a/src/commands/gxgames/commands/publish-impl.ts b/src/commands/gxgames/commands/publish-impl.ts index 7f35fb2..c003235 100644 --- a/src/commands/gxgames/commands/publish-impl.ts +++ b/src/commands/gxgames/commands/publish-impl.ts @@ -30,7 +30,7 @@ export default async function ( ): Promise { const projectDir = project ? this.path.dirname(project) : undefined; const link = await new LinkStorage(this, projectDir).read(); - const api = getApiClient(this, createAuthManager(this)); + const api = getApiClient(this, createAuthManager(this, projectDir)); const publishLog = this.makeTaskLogger("Publishing game"); const res = await api.publishGame(link.gameId); diff --git a/src/commands/gxgames/commands/upload-impl.ts b/src/commands/gxgames/commands/upload-impl.ts index 5dd014d..be24142 100644 --- a/src/commands/gxgames/commands/upload-impl.ts +++ b/src/commands/gxgames/commands/upload-impl.ts @@ -31,7 +31,7 @@ export default async function ( const projectDir = project ? this.path.dirname(project) : undefined; const link = await new LinkStorage(this, projectDir).read(); - const api = getApiClient(this, createAuthManager(this)); + const api = getApiClient(this, createAuthManager(this, projectDir)); const gamesRes = await api.getUserGames({ studioId: [link.studioId],