fix get blob data not working with civitai client cli

This commit is contained in:
Briant Diehl
2025-02-19 11:55:26 -07:00
parent 1f93463082
commit 437d162a35
2 changed files with 39 additions and 20 deletions
+7 -2
View File
@@ -3,8 +3,10 @@ import { withAxiom } from '@civitai/next-axiom';
import bundlAnalyzer from '@next/bundle-analyzer';
import packageJson from './package.json' assert { type: 'json' };
const analyze = process.env.ANALYZE === 'true';
const withBundleAnalyzer = bundlAnalyzer({
enabled: process.env.ANALYZE === 'true',
enabled: analyze,
});
/**
@@ -63,7 +65,10 @@ export default defineNextConfig(
experimental: {
// scrollRestoration: true,
largePageDataBytes: 512 * 100000,
optimizePackageImports: ['@civitai/client', './srs/libs/form'],
optimizePackageImports: [
'@civitai/client',
'./srs/libs/form'
],
},
headers: async () => {
// Add X-Robots-Tag header to all pages matching /sitemap.xml and /sitemap-models.xml /sitemap-articles.xml, etc
+32 -18
View File
@@ -11,27 +11,41 @@ export const nsfwNsfwLevels: NSFWLevel[] = ['r', 'x', 'xxx'];
export async function getBlobData({ token, blobId }: { token: string; blobId: string }) {
const client = createOrchestratorClient(token);
const { error, response } = await headBlob({
client,
path: { blobId },
}).catch((error) => {
throw error;
});
if (error) {
switch (error.status) {
case 400:
throw throwBadRequestError(error.detail);
case 401:
throw throwAuthorizationError(error.detail);
console.log(client.getConfig().baseUrl);
default:
if (error.detail?.startsWith('<!DOCTYPE'))
throw throwInternalServerError('Generation services down');
throw error;
}
}
const response = await fetch(`${client.getConfig().baseUrl}/v2/consumer/blobs/${blobId}`, {
headers: {
Authorization: `Bearer ${token}`,
},
});
if (!response.ok) throw new Error('unable to fetch blob data');
return {
nsfwLevel: response.headers.get('x-nsfw-level')?.toLocaleLowerCase() as NSFWLevel | null,
};
// const { error, data, response, request } = await headBlob({
// client,
// path: { blobId },
// }).catch((error) => {
// console.log('--------------------------');
// throw error;
// });
// if (error) {
// switch (error.status) {
// case 400:
// throw throwBadRequestError(error.detail);
// case 401:
// throw throwAuthorizationError(error.detail);
// default:
// if (error.detail?.startsWith('<!DOCTYPE'))
// throw throwInternalServerError('Generation services down');
// throw error;
// }
// }
// return {
// nsfwLevel: response.headers.get('x-nsfw-level')?.toLocaleLowerCase() as NSFWLevel | null,
// };
}