diff --git a/src/lib/config/Config.ts b/src/lib/config/Config.ts index b7f88c3..9491b10 100644 --- a/src/lib/config/Config.ts +++ b/src/lib/config/Config.ts @@ -120,6 +120,8 @@ export interface ConfigFeatures { headless: boolean; default_avatar: string; + + robots_txt: string; } export interface ConfigOAuth { diff --git a/src/lib/config/readConfig.ts b/src/lib/config/readConfig.ts index 1afcfa1..5e65d64 100644 --- a/src/lib/config/readConfig.ts +++ b/src/lib/config/readConfig.ts @@ -164,6 +164,8 @@ export default function readConfig() { map('FEATURES_DEFAULT_AVATAR', 'path', 'features.default_avatar'), + map('FEATURES_ROBOTS_TXT', 'boolean', 'features.robots_txt'), + map('CHUNKS_MAX_SIZE', 'human-to-byte', 'chunks.max_size'), map('CHUNKS_CHUNKS_SIZE', 'human-to-byte', 'chunks.chunks_size'), map('CHUNKS_ENABLED', 'boolean', 'chunks.enabled'), diff --git a/src/lib/config/validateConfig.ts b/src/lib/config/validateConfig.ts index 955ab46..57bab8e 100644 --- a/src/lib/config/validateConfig.ts +++ b/src/lib/config/validateConfig.ts @@ -4,7 +4,7 @@ import { inspect } from 'util'; import Logger from 'lib/logger'; import { humanToBytes } from 'utils/bytes'; import { tmpdir } from 'os'; -import { join } from 'path'; +import { join, resolve } from 'path'; const discord_content = s .object({ @@ -53,7 +53,7 @@ const validator = s.object({ type: s.enum('local', 's3', 'supabase').default('local'), local: s .object({ - directory: s.string.default('./uploads'), + directory: s.string.default(resolve('./uploads')).transform((v) => resolve(v)), }) .default({ directory: './uploads', @@ -195,6 +195,7 @@ const validator = s.object({ user_registration: s.boolean.default(false), headless: s.boolean.default(false), default_avatar: s.string.nullable.default(null), + robots_txt: s.boolean.default(false), }) .default({ invites: false, @@ -204,6 +205,7 @@ const validator = s.object({ user_registration: false, headless: false, default_avatar: null, + robots_txt: false, }), chunks: s .object({ diff --git a/src/lib/datasources/Local.ts b/src/lib/datasources/Local.ts index bfeb4f6..19e38f5 100644 --- a/src/lib/datasources/Local.ts +++ b/src/lib/datasources/Local.ts @@ -11,23 +11,23 @@ export class Local extends Datasource { } public async save(file: string, data: Buffer): Promise { - await writeFile(join(process.cwd(), this.path, file), data); + await writeFile(join(this.path, file), data); } public async delete(file: string): Promise { - await rm(join(process.cwd(), this.path, file)); + await rm(join(this.path, file)); } public async clear(): Promise { - const files = await readdir(join(process.cwd(), this.path)); + const files = await readdir(this.path); for (let i = 0; i !== files.length; ++i) { - await rm(join(process.cwd(), this.path, files[i])); + await rm(join(this.path, files[i])); } } public get(file: string): ReadStream { - const full = join(process.cwd(), this.path, file); + const full = join(this.path, file); if (!existsSync(full)) return null; try { @@ -38,7 +38,7 @@ export class Local extends Datasource { } public async size(file: string): Promise { - const full = join(process.cwd(), this.path, file); + const full = join(this.path, file); if (!existsSync(full)) return 0; const stats = await stat(full); diff --git a/src/pages/auth/login.tsx b/src/pages/auth/login.tsx index 6010719..06051b4 100644 --- a/src/pages/auth/login.tsx +++ b/src/pages/auth/login.tsx @@ -168,7 +168,7 @@ export default function Login({
- {bypass_local_login ? ' Login to Zipline with' : 'Zipline'} + {bypass_local_login ? ` Login to ${title} with` : title} {oauth_registration && ( diff --git a/src/server/index.ts b/src/server/index.ts index 090162b..e5eb8a0 100644 --- a/src/server/index.ts +++ b/src/server/index.ts @@ -100,6 +100,18 @@ async function start() { return reply.type('image/x-icon').send(favicon); }); + if (config.features.robots_txt) { + server.get('/robots.txt', async (_, reply) => { + return reply.type('text/plain').send(`User-Agent: * +Disallow: /r/ +Disallow: /api/ +Disallow: /view/ +Disallow: ${config.uploader.route} +Disallow: ${config.urls.route} +`); + }); + } + // makes sure to handle both in one route as you cant have two handlers with the same route if (config.urls.route === '/' && config.uploader.route === '/') { server.route({ diff --git a/src/worker/upload.ts b/src/worker/upload.ts index d6b26b1..8cbebed 100644 --- a/src/worker/upload.ts +++ b/src/worker/upload.ts @@ -84,7 +84,6 @@ async function start() { if (config.datasource.type === 'local') { fd = await open( join( - process.cwd(), config.datasource.local.directory, `${fileName}${compressionUsed ? '.jpg' : `${ext ? '.' : ''}${ext}`}` ),