Keep artifact list and beta queries free of file bytes
This commit is contained in:
@@ -2,14 +2,11 @@ import { json } from '@sveltejs/kit';
|
||||
import {
|
||||
createScript,
|
||||
isArtifactKind,
|
||||
listScripts,
|
||||
listVersions,
|
||||
serversMatchingScope,
|
||||
ScriptError,
|
||||
type ArtifactKind,
|
||||
type ScopeType
|
||||
} from '$lib/server/fleet/scripts.js';
|
||||
import { findRunningBetaForScript } from '$lib/server/fleet/beta.js';
|
||||
import { scriptCatalog } from '$lib/server/fleet/library-metadata.js';
|
||||
|
||||
function scopeTypeOrNull(v: FormDataEntryValue | null): ScopeType | null {
|
||||
if (v === null) return null;
|
||||
@@ -29,36 +26,7 @@ function kindOrDefault(v: FormDataEntryValue | string | null, fallback: Artifact
|
||||
export async function GET({ url }: { url: URL }) {
|
||||
const kindParam = url.searchParams.get('kind');
|
||||
const kindFilter = kindParam ? (isArtifactKind(kindParam) ? kindParam : null) : null;
|
||||
const rows = kindFilter ? listScripts(kindFilter) : listScripts();
|
||||
const scripts = rows.map((s) => {
|
||||
const versions = listVersions(s.id);
|
||||
const matched = s.scope_type && s.scope_value
|
||||
? serversMatchingScope(s.scope_type as ScopeType, s.scope_value)
|
||||
: [];
|
||||
const runningBeta = findRunningBetaForScript(s.id);
|
||||
const current = versions.find(v => v.id === s.current_version_id);
|
||||
return {
|
||||
...s,
|
||||
currentVersion: current ? {
|
||||
id: current.id, version: current.version, sha256: current.sha256,
|
||||
size: current.size, state: current.state, uploaded_at: current.uploaded_at
|
||||
} : null,
|
||||
latestVersion: versions[0]
|
||||
? {
|
||||
id: versions[0].id,
|
||||
version: versions[0].version,
|
||||
release_version: versions[0].release_version,
|
||||
sha256: versions[0].sha256,
|
||||
size: versions[0].size,
|
||||
state: versions[0].state,
|
||||
uploaded_at: versions[0].uploaded_at
|
||||
}
|
||||
: null,
|
||||
versionCount: versions.length,
|
||||
servers: matched,
|
||||
runningBetaId: runningBeta?.id ?? null
|
||||
};
|
||||
});
|
||||
const scripts = scriptCatalog(kindFilter ?? undefined);
|
||||
return json({ scripts });
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user