* fix: - readd root route for uploads only - catch 1 edge case for root route (/dashboard) * fix: spelt dashboard right * fix: include the dot for the extension * fix: remove any possible references of swift * fix: missed a spot * Update .env.local.example Co-authored-by: Jonathan <axis@axis.moe> * Update .env.local.example * Update validateConfig.ts * format Co-authored-by: dicedtomato <35403473+diced@users.noreply.github.com> Co-authored-by: Jonathan <axis@axis.moe>
This commit is contained in:
parent
f07cbeac52
commit
a75b790654
5 changed files with 38 additions and 61 deletions
|
@ -1,7 +1,7 @@
|
|||
# every field in here is optional except, CORE_SECRET and CORE_DATABASE_URL.
|
||||
# if CORE_SECRET is still "changethis" then zipline will exit and tell you to change it.
|
||||
|
||||
# if using s3/swift make sure to comment out the other datasources
|
||||
# if using s3/supabase make sure to comment out the other datasources
|
||||
|
||||
CORE_HTTPS=true
|
||||
CORE_SECRET="changethis"
|
||||
|
@ -25,14 +25,12 @@ DATASOURCE_S3_REGION=us-west-2
|
|||
DATASOURCE_S3_FORCE_S3_PATH=false
|
||||
DATASOURCE_S3_USE_SSL=false
|
||||
|
||||
# or you can use swift
|
||||
DATASOURCE_TYPE=swift
|
||||
DATASOURCE_SWIFT_CONTAINER=container
|
||||
DATASOURCE_SWIFT_AUTH_ENDPOINT="https://something/v3"
|
||||
DATASOURCE_SWIFT_USERNAME=username
|
||||
DATASOURCE_SWIFT_PASSWORD=password
|
||||
DATASOURCE_SWIFT_PROJECT_ID=project_id
|
||||
DATASOURCE_SWIFT_DOMAIN_ID=domain_id
|
||||
# or supabase
|
||||
DATASOURCE_TYPE=supabase
|
||||
DATASOURCE_SUPABASE_KEY=xxx
|
||||
# remember: no leading slash
|
||||
DATASOURCE_SUPABASE_URL=https://something.supabase.co
|
||||
DATASOURCE_SUPABASE_BUCKET=zipline
|
||||
|
||||
UPLOADER_DEFAULT_FORMAT=RANDOM
|
||||
UPLOADER_ROUTE=/u
|
||||
|
|
|
@ -32,16 +32,6 @@ export interface ConfigS3Datasource {
|
|||
region?: string;
|
||||
}
|
||||
|
||||
export interface ConfigSwiftDatasource {
|
||||
container: string;
|
||||
auth_endpoint: string;
|
||||
username: string;
|
||||
password: string;
|
||||
project_id: string;
|
||||
domain_id?: string;
|
||||
region_id?: string;
|
||||
}
|
||||
|
||||
export interface ConfigSupabaseDatasource {
|
||||
url: string;
|
||||
key: string;
|
||||
|
|
|
@ -34,7 +34,7 @@ const validator = s.object({
|
|||
}),
|
||||
datasource: s
|
||||
.object({
|
||||
type: s.enum('local', 's3', 'swift', 'supabase').default('local'),
|
||||
type: s.enum('local', 's3', 'supabase').default('local'),
|
||||
local: s
|
||||
.object({
|
||||
directory: s.string.default('./uploads'),
|
||||
|
@ -52,15 +52,6 @@ const validator = s.object({
|
|||
region: s.string.default('us-east-1'),
|
||||
use_ssl: s.boolean.default(false),
|
||||
}).optional,
|
||||
swift: s.object({
|
||||
username: s.string,
|
||||
password: s.string,
|
||||
auth_endpoint: s.string,
|
||||
container: s.string,
|
||||
project_id: s.string,
|
||||
domain_id: s.string.default('default'),
|
||||
region_id: s.string.nullable,
|
||||
}).optional,
|
||||
supabase: s.object({
|
||||
url: s.string,
|
||||
key: s.string,
|
||||
|
@ -76,9 +67,6 @@ const validator = s.object({
|
|||
region: 'us-east-1',
|
||||
force_s3_path: false,
|
||||
},
|
||||
swift: {
|
||||
domain_id: 'default',
|
||||
},
|
||||
}),
|
||||
uploader: s
|
||||
.object({
|
||||
|
@ -233,19 +221,15 @@ export default function validate(config): Config {
|
|||
if (errors.length) throw { errors };
|
||||
break;
|
||||
}
|
||||
case 'swift': {
|
||||
case 'supabase': {
|
||||
const errors = [];
|
||||
if (!validated.datasource.swift.container)
|
||||
errors.push('datasource.swift.container is a required field');
|
||||
if (!validated.datasource.swift.project_id)
|
||||
errors.push('datasource.swift.project_id is a required field');
|
||||
if (!validated.datasource.swift.auth_endpoint)
|
||||
errors.push('datasource.swift.auth_endpoint is a required field');
|
||||
if (!validated.datasource.swift.password)
|
||||
errors.push('datasource.swift.password is a required field');
|
||||
if (!validated.datasource.swift.username)
|
||||
errors.push('datasource.swift.username is a required field');
|
||||
|
||||
if (!validated.datasource.supabase.key) errors.push('datasource.supabase.key is a required field');
|
||||
if (!validated.datasource.supabase.url) errors.push('datasource.supabase.url is a required field');
|
||||
if (!validated.datasource.supabase.bucket)
|
||||
errors.push('datasource.supabase.bucket is a required field');
|
||||
if (errors.length) throw { errors };
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -149,7 +149,7 @@ async function handler(req: NextApiReq, res: NextApiRes) {
|
|||
|
||||
const file = await prisma.image.create({
|
||||
data: {
|
||||
file: `${fileName}${compressionUsed ? '.jpg' : ext ?? ''}`,
|
||||
file: `${fileName}${compressionUsed ? '.jpg' : `${ext ? '.' : ''}${ext}`}`,
|
||||
mimetype,
|
||||
userId: user.id,
|
||||
embed: !!req.headers.embed,
|
||||
|
@ -273,7 +273,7 @@ async function handler(req: NextApiReq, res: NextApiRes) {
|
|||
let invis: InvisibleImage;
|
||||
const image = await prisma.image.create({
|
||||
data: {
|
||||
file: `${fileName}${compressionUsed ? '.jpg' : ext ?? ''}`,
|
||||
file: `${fileName}${compressionUsed ? '.jpg' : `${ext ? '.' : ''}${ext}`}`,
|
||||
mimetype: req.headers.uploadtext ? 'text/plain' : compressionUsed ? 'image/jpeg' : file.mimetype,
|
||||
userId: user.id,
|
||||
embed: !!req.headers.embed,
|
||||
|
|
|
@ -118,27 +118,32 @@ async function start() {
|
|||
return redirect(res, url.destination);
|
||||
});
|
||||
|
||||
router.on('GET', `${config.uploader.route}/:id`, async (req, res, params) => {
|
||||
if (params.id === '') return nextServer.render404(req, res as ServerResponse);
|
||||
router.on(
|
||||
'GET',
|
||||
config.uploader.route === '/' ? '/:id' : `${config.uploader.route}/:id`,
|
||||
async (req, res, params) => {
|
||||
if (params.id === '') return nextServer.render404(req, res as ServerResponse);
|
||||
else if (params.id === 'dashboard') return nextServer.render(req, res as ServerResponse, '/dashboard');
|
||||
|
||||
const image = await prisma.image.findFirst({
|
||||
where: {
|
||||
OR: [{ file: params.id }, { invisible: { invis: decodeURI(params.id) } }],
|
||||
},
|
||||
});
|
||||
const image = await prisma.image.findFirst({
|
||||
where: {
|
||||
OR: [{ file: params.id }, { invisible: { invis: decodeURI(params.id) } }],
|
||||
},
|
||||
});
|
||||
|
||||
if (!image) return rawFile(req, res, nextServer, params.id);
|
||||
else {
|
||||
const failed = await preFile(image, prisma);
|
||||
if (failed) return nextServer.render404(req, res as ServerResponse);
|
||||
if (!image) return rawFile(req, res, nextServer, params.id);
|
||||
else {
|
||||
const failed = await preFile(image, prisma);
|
||||
if (failed) return nextServer.render404(req, res as ServerResponse);
|
||||
|
||||
if (image.password || image.embed || image.mimetype.startsWith('text/'))
|
||||
redirect(res, `/view/${image.file}`);
|
||||
else fileDb(req, res, nextServer, handle, image);
|
||||
if (image.password || image.embed || image.mimetype.startsWith('text/'))
|
||||
redirect(res, `/view/${image.file}`);
|
||||
else fileDb(req, res, nextServer, handle, image);
|
||||
|
||||
postFile(image, prisma);
|
||||
postFile(image, prisma);
|
||||
}
|
||||
}
|
||||
});
|
||||
);
|
||||
|
||||
router.on('GET', '/r/:id', async (req, res, params) => {
|
||||
if (params.id === '') return nextServer.render404(req, res as ServerResponse);
|
||||
|
|
Loading…
Reference in a new issue