Adding robots.txt override via admin control panel
This is a requested low priority feature in #418 - I created the changes to follow similarly to how the Instance Description is handled.
This commit is contained in:
parent
4b104879cd
commit
993532bc1f
10 changed files with 62 additions and 1 deletions
16
packages/backend/migration/1738098171990-robotsTxt.js
Normal file
16
packages/backend/migration/1738098171990-robotsTxt.js
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: marie and other Sharkey contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
export class RobotsTxt1738098171990 {
|
||||
name = 'RobotsTxt1738098171990'
|
||||
|
||||
async up(queryRunner) {
|
||||
await queryRunner.query(`ALTER TABLE "meta" ADD "robotsTxt" character varying(2048)`);
|
||||
}
|
||||
|
||||
async down(queryRunner) {
|
||||
await queryRunner.query(`ALTER TABLE "meta" DROP COLUMN "robotsTxt"`);
|
||||
}
|
||||
}
|
||||
|
|
@ -95,6 +95,7 @@ export class MetaEntityService {
|
|||
mcaptchaInstanceUrl: instance.mcaptchaInstanceUrl,
|
||||
enableRecaptcha: instance.enableRecaptcha,
|
||||
enableAchievements: instance.enableAchievements,
|
||||
robotsTxt: instance.robotsTxt,
|
||||
recaptchaSiteKey: instance.recaptchaSiteKey,
|
||||
enableTurnstile: instance.enableTurnstile,
|
||||
turnstileSiteKey: instance.turnstileSiteKey,
|
||||
|
|
|
|||
|
|
@ -599,6 +599,11 @@ export class MiMeta {
|
|||
})
|
||||
public enableAchievements: boolean;
|
||||
|
||||
@Column('varchar', {
|
||||
length: 2048, nullable: true,
|
||||
})
|
||||
public robotsTxt: string | null;
|
||||
|
||||
@Column('jsonb', {
|
||||
default: { },
|
||||
})
|
||||
|
|
|
|||
|
|
@ -139,6 +139,10 @@ export const packedMetaLiteSchema = {
|
|||
type: 'boolean',
|
||||
optional: false, nullable: true,
|
||||
},
|
||||
robotsTxt: {
|
||||
type: 'string',
|
||||
optional: false, nullable: true,
|
||||
},
|
||||
enableTestcaptcha: {
|
||||
type: 'boolean',
|
||||
optional: false, nullable: false,
|
||||
|
|
|
|||
|
|
@ -391,6 +391,10 @@ export const meta = {
|
|||
type: 'boolean',
|
||||
optional: false, nullable: false,
|
||||
},
|
||||
robotsTxt: {
|
||||
type: 'string',
|
||||
optional: false, nullable: true,
|
||||
},
|
||||
enableIdenticonGeneration: {
|
||||
type: 'boolean',
|
||||
optional: false, nullable: false,
|
||||
|
|
@ -708,6 +712,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
|
|||
enableStatsForFederatedInstances: instance.enableStatsForFederatedInstances,
|
||||
enableServerMachineStats: instance.enableServerMachineStats,
|
||||
enableAchievements: instance.enableAchievements,
|
||||
robotsTxt: instance.robotsTxt,
|
||||
enableIdenticonGeneration: instance.enableIdenticonGeneration,
|
||||
bannedEmailDomains: instance.bannedEmailDomains,
|
||||
policies: { ...DEFAULT_POLICIES, ...instance.policies },
|
||||
|
|
|
|||
|
|
@ -149,6 +149,7 @@ export const paramDef = {
|
|||
enableStatsForFederatedInstances: { type: 'boolean' },
|
||||
enableServerMachineStats: { type: 'boolean' },
|
||||
enableAchievements: { type: 'boolean' },
|
||||
robotsTxt: { type: 'string', nullable: true },
|
||||
enableIdenticonGeneration: { type: 'boolean' },
|
||||
serverRules: { type: 'array', items: { type: 'string' } },
|
||||
bannedEmailDomains: { type: 'array', items: { type: 'string' } },
|
||||
|
|
@ -636,6 +637,10 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
|
|||
set.enableAchievements = ps.enableAchievements;
|
||||
}
|
||||
|
||||
if (ps.robotsTxt !== undefined) {
|
||||
set.robotsTxt = ps.robotsTxt;
|
||||
}
|
||||
|
||||
if (ps.enableIdenticonGeneration !== undefined) {
|
||||
set.enableIdenticonGeneration = ps.enableIdenticonGeneration;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -488,7 +488,14 @@ export class ClientServerService {
|
|||
});
|
||||
|
||||
fastify.get('/robots.txt', async (request, reply) => {
|
||||
return await reply.sendFile('/robots.txt', staticAssets);
|
||||
if (this.meta.robotsTxt) {
|
||||
let content = '';
|
||||
content += this.meta.robotsTxt;
|
||||
reply.header('Content-Type', 'text/plain');
|
||||
return await reply.send(content);
|
||||
} else {
|
||||
return await reply.sendFile('/robots.txt', staticAssets);
|
||||
}
|
||||
});
|
||||
|
||||
// OpenSearch XML
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue