feat: add admin accounts and image templates
This commit is contained in:
@@ -1,14 +1,15 @@
|
||||
import { getAsset, listAssets, listGenerationJobsFiltered } from "@/lib/server/data-store";
|
||||
import { DEFAULT_OWNER_ID } from "@/lib/server/runtime";
|
||||
import { publicApiOwnerId } from "@/lib/server/public-api-auth";
|
||||
import type { Asset, GenerationJob } from "@/lib/types";
|
||||
|
||||
const JOB_LOOKUP_LIMIT = 200;
|
||||
|
||||
export async function listPublicApiAssets(clientId: string): Promise<Asset[]> {
|
||||
const ownerId = publicApiOwnerId(clientId);
|
||||
const [assets, jobs] = await Promise.all([
|
||||
listAssets(DEFAULT_OWNER_ID),
|
||||
listAssets(ownerId),
|
||||
listGenerationJobsFiltered({
|
||||
ownerId: DEFAULT_OWNER_ID,
|
||||
ownerId,
|
||||
externalClientId: clientId,
|
||||
limit: JOB_LOOKUP_LIMIT
|
||||
})
|
||||
@@ -18,11 +19,12 @@ export async function listPublicApiAssets(clientId: string): Promise<Asset[]> {
|
||||
}
|
||||
|
||||
export async function getPublicApiAsset(clientId: string, assetId: string): Promise<Asset | null> {
|
||||
const ownerId = publicApiOwnerId(clientId);
|
||||
const asset = await getAsset(assetId);
|
||||
if (!asset || asset.ownerId !== DEFAULT_OWNER_ID) return null;
|
||||
if (!asset || asset.ownerId !== ownerId) return null;
|
||||
if (asset.tags.includes(apiClientTag(clientId))) return asset;
|
||||
const jobs = await listGenerationJobsFiltered({
|
||||
ownerId: DEFAULT_OWNER_ID,
|
||||
ownerId,
|
||||
externalClientId: clientId,
|
||||
limit: JOB_LOOKUP_LIMIT
|
||||
});
|
||||
@@ -30,10 +32,7 @@ export async function getPublicApiAsset(clientId: string, assetId: string): Prom
|
||||
}
|
||||
|
||||
function canAccessAsset(clientId: string, asset: Asset, accessibleIds: Set<string>): boolean {
|
||||
return asset.ownerId === DEFAULT_OWNER_ID && (
|
||||
asset.tags.includes(apiClientTag(clientId)) ||
|
||||
accessibleIds.has(asset.id)
|
||||
);
|
||||
return asset.tags.includes(apiClientTag(clientId)) || accessibleIds.has(asset.id);
|
||||
}
|
||||
|
||||
function assetIdsFromJobs(jobs: GenerationJob[]): Set<string> {
|
||||
|
||||
Reference in New Issue
Block a user