mirror of
https://github.com/civitai/civitai.git
synced 2026-09-20 22:08:18 +08:00
Enables file uploading through minio
This commit is contained in:
+8
-10
@@ -48,17 +48,16 @@ S3_UPLOAD_KEY=REFER_TO_README
|
||||
S3_UPLOAD_SECRET=REFER_TO_README
|
||||
S3_UPLOAD_BUCKET=modelshare
|
||||
S3_UPLOAD_REGION=us-east-1
|
||||
S3_UPLOAD_ENDPOINT=http://localhost:9000
|
||||
S3_SETTLED_BUCKET=settled
|
||||
S3_UPLOAD_ENDPOINT=http://127.0.0.1:9000
|
||||
S3_ORIGINS=http://localhost:3000
|
||||
S3_FORCE_PATH_STYLE=true
|
||||
|
||||
# Image uploading
|
||||
S3_IMAGE_UPLOAD_KEY=
|
||||
S3_IMAGE_UPLOAD_SECRET=
|
||||
S3_IMAGE_UPLOAD_REGION=
|
||||
S3_IMAGE_UPLOAD_ENDPOINT=http://localhost:9000
|
||||
S3_IMAGE_UPLOAD_BUCKET=images
|
||||
S3_IMAGE_UPLOAD_REGION=us-east-1
|
||||
S3_IMAGE_UPLOAD_ENDPOINT=http://127.0.0.1:9000
|
||||
S3_IMAGE_CACHE_BUCKET=cache
|
||||
S3_IMAGE_UPLOAD_OVERRIDE=
|
||||
|
||||
@@ -105,11 +104,10 @@ DELIVERY_WORKER_ENDPOINT=https://delivery-worker.civitai.com/download
|
||||
DELIVERY_WORKER_TOKEN=thisisnotatoken
|
||||
|
||||
# Payments
|
||||
STRIPE_SECRET_KEY=thisisnotakey
|
||||
STRIPE_WEBHOOK_SECRET=thisisnotasecret
|
||||
STRIPE_CONNECT_WEBHOOK_SECRET=thisisnotasecret
|
||||
STRIPE_DONATE_ID=price_1MZHyDLAn4if8jivVbH5PhMc
|
||||
TIER_METADATA_KEY=tier
|
||||
PADDLE_SECRET_KEY=thisisnotasecret
|
||||
PADDLE_WEBHOOK_SECRET=thisisnotasecret
|
||||
NEXT_PUBLIC_PADDLE_TOKEN=thisisnotatoken
|
||||
NEXT_PUBLIC_DEFAULT_PAYMENT_PROVIDER=Paddle
|
||||
|
||||
# Features
|
||||
FEATURE_FLAG_EARLY_ACCESS_MODEL=public
|
||||
@@ -121,7 +119,7 @@ NEXT_PUBLIC_SEARCH_HOST=https://localhost:7700
|
||||
NEXT_PUBLIC_SEARCH_CLIENT_KEY=meilisearch
|
||||
|
||||
METRICS_SEARCH_HOST=https://localhost:7700
|
||||
METRICS_SEARCH_API_KEY= meilisearch
|
||||
METRICS_SEARCH_API_KEY=meilisearch
|
||||
|
||||
# BaseURL
|
||||
NEXT_PUBLIC_BASE_URL=http://localhost:3000
|
||||
|
||||
+1
-1
@@ -75,7 +75,7 @@ services:
|
||||
# depends_on:
|
||||
# - minio
|
||||
# entrypoint: >
|
||||
# /bin/sh -c " /usr/bin/mc config host add minio http://minio:9000 minioadmin minioadmin && /usr/bin/mc mb minio/modelshare && /usr/bin/mc policy set public minio/modelshare && /usr/bin/mc mb minio/settled && /usr/bin/mc policy set public minio/settled && exit 0"
|
||||
# /bin/sh -c " /usr/bin/mc config host add minio http://minio:9000 minioadmin minioadmin && /usr/bin/mc mb minio/modelshare && /usr/bin/mc policy set public minio/modelshare && /usr/bin/mc mb minio/images && /usr/bin/mc policy set public minio/images && exit 0"
|
||||
# restart: unless-stopped
|
||||
|
||||
maildev:
|
||||
|
||||
Vendored
+7
-8
@@ -8,7 +8,7 @@ import { env as clientEnv, formatErrors } from './client.mjs';
|
||||
import { serverSchema } from './schema.mjs';
|
||||
|
||||
if (process.env.NODE_ENV === 'development') {
|
||||
dotenv.config({ path: ['.env.development.local', '.env.local', '.env.development', '.env'] });
|
||||
dotenv.config({ path: ['.env.development.local', '.env.local', '.env.development', '.env'], override: false });
|
||||
}
|
||||
|
||||
const _serverEnv = serverSchema.safeParse(process.env);
|
||||
@@ -33,18 +33,17 @@ if (process.env.NODE_ENV === 'development') {
|
||||
console.log('Unknown database connection');
|
||||
} else {
|
||||
console.log(
|
||||
`Using ${
|
||||
dbUser[1] === 'postgres'
|
||||
? 'LOCAL'
|
||||
: dbUser[1] === 'doadmin'
|
||||
`Using ${dbUser[1] === 'postgres'
|
||||
? 'LOCAL'
|
||||
: dbUser[1] === 'doadmin'
|
||||
? 'DEV'
|
||||
: dbUser[1] === 'civitai'
|
||||
? 'PROD'
|
||||
: 'UNKNOWN'
|
||||
? 'PROD'
|
||||
: 'UNKNOWN'
|
||||
} database.`
|
||||
);
|
||||
}
|
||||
} catch {}
|
||||
} catch { }
|
||||
}
|
||||
|
||||
export const env = { ..._serverEnv.data, ...clientEnv };
|
||||
|
||||
@@ -10,26 +10,36 @@ const s3Domain = (env.S3_IMAGE_UPLOAD_ENDPOINT ?? env.S3_UPLOAD_ENDPOINT).replac
|
||||
);
|
||||
|
||||
export default async function imageUploadMultipart(req: NextApiRequest, res: NextApiResponse) {
|
||||
const session = await getServerAuthSession({ req, res });
|
||||
const userId = session?.user?.id;
|
||||
if (!userId || session.user?.bannedAt || session.user?.muted) {
|
||||
res.status(401).json({ error: 'Unauthorized' });
|
||||
return;
|
||||
try {
|
||||
const session = await getServerAuthSession({ req, res });
|
||||
const userId = session?.user?.id;
|
||||
if (!userId || session.user?.bannedAt || session.user?.muted) {
|
||||
res.status(401).json({ error: 'Unauthorized' });
|
||||
return;
|
||||
}
|
||||
|
||||
const imageKey = randomUUID();
|
||||
const s3 = getS3Client('image');
|
||||
const result = await getMultipartPutUrl(
|
||||
imageKey,
|
||||
req.body.size,
|
||||
s3,
|
||||
env.S3_IMAGE_UPLOAD_BUCKET
|
||||
);
|
||||
|
||||
if (env.S3_IMAGE_UPLOAD_OVERRIDE) {
|
||||
result.urls = result.urls.map((item) => ({
|
||||
...item,
|
||||
url: item.url.replace(
|
||||
`${env.S3_IMAGE_UPLOAD_BUCKET}.${s3Domain}`,
|
||||
env.S3_IMAGE_UPLOAD_OVERRIDE as string
|
||||
),
|
||||
}));
|
||||
}
|
||||
|
||||
res.status(200).json(result);
|
||||
} catch (error) {
|
||||
const e = error as Error;
|
||||
return res.status(500).json({ error: e.message });
|
||||
}
|
||||
|
||||
const imageKey = randomUUID();
|
||||
const s3 = getS3Client('image');
|
||||
const result = await getMultipartPutUrl(imageKey, req.body.size, s3, env.S3_IMAGE_UPLOAD_BUCKET);
|
||||
|
||||
if (env.S3_IMAGE_UPLOAD_OVERRIDE) {
|
||||
result.urls = result.urls.map((item) => ({
|
||||
...item,
|
||||
url: item.url.replace(
|
||||
`${env.S3_IMAGE_UPLOAD_BUCKET}.${s3Domain}`,
|
||||
env.S3_IMAGE_UPLOAD_OVERRIDE as string
|
||||
),
|
||||
}));
|
||||
}
|
||||
|
||||
res.status(200).json(result);
|
||||
}
|
||||
|
||||
@@ -65,9 +65,9 @@ const featureFlags = createFeatureFlags({
|
||||
},
|
||||
profileCollections: ['public'],
|
||||
imageSearch: ['dev'],
|
||||
buzz: isDev ? ['granted', 'public'] : ['public'],
|
||||
signal: isDev ? ['granted', 'user'] : ['user'],
|
||||
recommenders: isDev ? ['granted', 'dev', 'mod'] : ['dev', 'mod'],
|
||||
buzz: isDev ? ['granted'] : ['public'],
|
||||
signal: isDev ? ['granted'] : ['user'],
|
||||
recommenders: isDev ? ['granted'] : ['dev', 'mod'],
|
||||
assistant: {
|
||||
toggleable: true,
|
||||
default: true,
|
||||
|
||||
Reference in New Issue
Block a user