* 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.
|
# 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 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_HTTPS=true
|
||||||
CORE_SECRET="changethis"
|
CORE_SECRET="changethis"
|
||||||
|
@ -25,14 +25,12 @@ DATASOURCE_S3_REGION=us-west-2
|
||||||
DATASOURCE_S3_FORCE_S3_PATH=false
|
DATASOURCE_S3_FORCE_S3_PATH=false
|
||||||
DATASOURCE_S3_USE_SSL=false
|
DATASOURCE_S3_USE_SSL=false
|
||||||
|
|
||||||
# or you can use swift
|
# or supabase
|
||||||
DATASOURCE_TYPE=swift
|
DATASOURCE_TYPE=supabase
|
||||||
DATASOURCE_SWIFT_CONTAINER=container
|
DATASOURCE_SUPABASE_KEY=xxx
|
||||||
DATASOURCE_SWIFT_AUTH_ENDPOINT="https://something/v3"
|
# remember: no leading slash
|
||||||
DATASOURCE_SWIFT_USERNAME=username
|
DATASOURCE_SUPABASE_URL=https://something.supabase.co
|
||||||
DATASOURCE_SWIFT_PASSWORD=password
|
DATASOURCE_SUPABASE_BUCKET=zipline
|
||||||
DATASOURCE_SWIFT_PROJECT_ID=project_id
|
|
||||||
DATASOURCE_SWIFT_DOMAIN_ID=domain_id
|
|
||||||
|
|
||||||
UPLOADER_DEFAULT_FORMAT=RANDOM
|
UPLOADER_DEFAULT_FORMAT=RANDOM
|
||||||
UPLOADER_ROUTE=/u
|
UPLOADER_ROUTE=/u
|
||||||
|
|
|
@ -32,16 +32,6 @@ export interface ConfigS3Datasource {
|
||||||
region?: string;
|
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 {
|
export interface ConfigSupabaseDatasource {
|
||||||
url: string;
|
url: string;
|
||||||
key: string;
|
key: string;
|
||||||
|
|
|
@ -34,7 +34,7 @@ const validator = s.object({
|
||||||
}),
|
}),
|
||||||
datasource: s
|
datasource: s
|
||||||
.object({
|
.object({
|
||||||
type: s.enum('local', 's3', 'swift', 'supabase').default('local'),
|
type: s.enum('local', 's3', 'supabase').default('local'),
|
||||||
local: s
|
local: s
|
||||||
.object({
|
.object({
|
||||||
directory: s.string.default('./uploads'),
|
directory: s.string.default('./uploads'),
|
||||||
|
@ -52,15 +52,6 @@ const validator = s.object({
|
||||||
region: s.string.default('us-east-1'),
|
region: s.string.default('us-east-1'),
|
||||||
use_ssl: s.boolean.default(false),
|
use_ssl: s.boolean.default(false),
|
||||||
}).optional,
|
}).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({
|
supabase: s.object({
|
||||||
url: s.string,
|
url: s.string,
|
||||||
key: s.string,
|
key: s.string,
|
||||||
|
@ -76,9 +67,6 @@ const validator = s.object({
|
||||||
region: 'us-east-1',
|
region: 'us-east-1',
|
||||||
force_s3_path: false,
|
force_s3_path: false,
|
||||||
},
|
},
|
||||||
swift: {
|
|
||||||
domain_id: 'default',
|
|
||||||
},
|
|
||||||
}),
|
}),
|
||||||
uploader: s
|
uploader: s
|
||||||
.object({
|
.object({
|
||||||
|
@ -233,19 +221,15 @@ export default function validate(config): Config {
|
||||||
if (errors.length) throw { errors };
|
if (errors.length) throw { errors };
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'swift': {
|
case 'supabase': {
|
||||||
const errors = [];
|
const errors = [];
|
||||||
if (!validated.datasource.swift.container)
|
|
||||||
errors.push('datasource.swift.container is a required field');
|
if (!validated.datasource.supabase.key) errors.push('datasource.supabase.key is a required field');
|
||||||
if (!validated.datasource.swift.project_id)
|
if (!validated.datasource.supabase.url) errors.push('datasource.supabase.url is a required field');
|
||||||
errors.push('datasource.swift.project_id is a required field');
|
if (!validated.datasource.supabase.bucket)
|
||||||
if (!validated.datasource.swift.auth_endpoint)
|
errors.push('datasource.supabase.bucket is a required field');
|
||||||
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 (errors.length) throw { errors };
|
if (errors.length) throw { errors };
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -149,7 +149,7 @@ async function handler(req: NextApiReq, res: NextApiRes) {
|
||||||
|
|
||||||
const file = await prisma.image.create({
|
const file = await prisma.image.create({
|
||||||
data: {
|
data: {
|
||||||
file: `${fileName}${compressionUsed ? '.jpg' : ext ?? ''}`,
|
file: `${fileName}${compressionUsed ? '.jpg' : `${ext ? '.' : ''}${ext}`}`,
|
||||||
mimetype,
|
mimetype,
|
||||||
userId: user.id,
|
userId: user.id,
|
||||||
embed: !!req.headers.embed,
|
embed: !!req.headers.embed,
|
||||||
|
@ -273,7 +273,7 @@ async function handler(req: NextApiReq, res: NextApiRes) {
|
||||||
let invis: InvisibleImage;
|
let invis: InvisibleImage;
|
||||||
const image = await prisma.image.create({
|
const image = await prisma.image.create({
|
||||||
data: {
|
data: {
|
||||||
file: `${fileName}${compressionUsed ? '.jpg' : ext ?? ''}`,
|
file: `${fileName}${compressionUsed ? '.jpg' : `${ext ? '.' : ''}${ext}`}`,
|
||||||
mimetype: req.headers.uploadtext ? 'text/plain' : compressionUsed ? 'image/jpeg' : file.mimetype,
|
mimetype: req.headers.uploadtext ? 'text/plain' : compressionUsed ? 'image/jpeg' : file.mimetype,
|
||||||
userId: user.id,
|
userId: user.id,
|
||||||
embed: !!req.headers.embed,
|
embed: !!req.headers.embed,
|
||||||
|
|
|
@ -118,27 +118,32 @@ async function start() {
|
||||||
return redirect(res, url.destination);
|
return redirect(res, url.destination);
|
||||||
});
|
});
|
||||||
|
|
||||||
router.on('GET', `${config.uploader.route}/:id`, async (req, res, params) => {
|
router.on(
|
||||||
if (params.id === '') return nextServer.render404(req, res as ServerResponse);
|
'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({
|
const image = await prisma.image.findFirst({
|
||||||
where: {
|
where: {
|
||||||
OR: [{ file: params.id }, { invisible: { invis: decodeURI(params.id) } }],
|
OR: [{ file: params.id }, { invisible: { invis: decodeURI(params.id) } }],
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!image) return rawFile(req, res, nextServer, params.id);
|
if (!image) return rawFile(req, res, nextServer, params.id);
|
||||||
else {
|
else {
|
||||||
const failed = await preFile(image, prisma);
|
const failed = await preFile(image, prisma);
|
||||||
if (failed) return nextServer.render404(req, res as ServerResponse);
|
if (failed) return nextServer.render404(req, res as ServerResponse);
|
||||||
|
|
||||||
if (image.password || image.embed || image.mimetype.startsWith('text/'))
|
if (image.password || image.embed || image.mimetype.startsWith('text/'))
|
||||||
redirect(res, `/view/${image.file}`);
|
redirect(res, `/view/${image.file}`);
|
||||||
else fileDb(req, res, nextServer, handle, image);
|
else fileDb(req, res, nextServer, handle, image);
|
||||||
|
|
||||||
postFile(image, prisma);
|
postFile(image, prisma);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
);
|
||||||
|
|
||||||
router.on('GET', '/r/:id', async (req, res, params) => {
|
router.on('GET', '/r/:id', async (req, res, params) => {
|
||||||
if (params.id === '') return nextServer.render404(req, res as ServerResponse);
|
if (params.id === '') return nextServer.render404(req, res as ServerResponse);
|
||||||
|
|
Loading…
Add table
Reference in a new issue