refactor: make post imports an experiment

This commit is contained in:
ThatOneCalculator 2023-05-25 22:05:43 -07:00
parent 8783cf0adf
commit afa15e17ef
No known key found for this signature in database
GPG key ID: 8703CACD01000000
6 changed files with 44 additions and 1 deletions

View file

@ -479,6 +479,9 @@ export const meta = {
postEditing: {
type: "boolean",
},
postImports: {
type: "boolean",
},
},
},
},

View file

@ -175,6 +175,7 @@ export const paramDef = {
nullable: true,
properties: {
postEditing: { type: "boolean" },
postImports: { type: "boolean" },
},
},
},

View file

@ -3,6 +3,7 @@ import { createImportPostsJob } from "@/queue/index.js";
import { ApiError } from "../../error.js";
import { DriveFiles } from "@/models/index.js";
import { DAY } from "@/const.js";
import { fetchMeta } from "@/misc/fetch-meta.js";
export const meta = {
secure: true,
@ -23,6 +24,12 @@ export const meta = {
code: "EMPTY_FILE",
id: "d2f12af1-e7b4-feac-86a3-519548f2728e",
},
importsDisabled: {
message: "Post imports are disabled.",
code: "IMPORTS_DISABLED",
id: " bc9227e4-fb82-11ed-be56-0242ac120002",
},
},
} as const;
@ -38,6 +45,10 @@ export const paramDef = {
export default define(meta, paramDef, async (ps, user) => {
const file = await DriveFiles.findOneBy({ id: ps.fileId });
const instanceMeta = await fetchMeta();
if (instanceMeta.experimentalFeatures?.postImports === false)
throw new ApiError(meta.errors.importsDisabled);
if (file == null) throw new ApiError(meta.errors.noSuchFile);
if (file.size === 0) throw new ApiError(meta.errors.emptyFile);
createImportPostsJob(user, file.id, ps.signatureCheck);

View file

@ -524,6 +524,7 @@ export default define(meta, paramDef, async (ps, me) => {
discord: instance.enableDiscordIntegration,
serviceWorker: instance.enableServiceWorker,
postEditing: instance.experimentalFeatures?.postEditing || false,
postImports: instance.experimentalFeatures?.postImports || false,
miauth: true,
};
}

View file

@ -33,6 +33,7 @@ import { renderActivity } from "@/remote/activitypub/renderer/index.js";
import renderNote from "@/remote/activitypub/renderer/note.js";
import renderUpdate from "@/remote/activitypub/renderer/update.js";
import { deliverToRelays } from "@/services/relay.js";
import { fetchMeta } from "@/misc/fetch-meta.js";
export const meta = {
tags: ["notes"],
@ -138,6 +139,12 @@ export const meta = {
code: "NOT_LOCAL_USER",
id: "b907f407-2aa0-4283-800b-a2c56290b822",
},
editsDisabled: {
message: "Post edits are disabled.",
code: "EDITS_DISABLED",
id: "99306f00-fb81-11ed-be56-0242ac120002",
},
},
} as const;
@ -236,6 +243,10 @@ export const paramDef = {
export default define(meta, paramDef, async (ps, user) => {
if (user.movedToUri != null) throw new ApiError(meta.errors.accountLocked);
const instanceMeta = await fetchMeta();
if (instanceMeta.experimentalFeatures?.postImports === false)
throw new ApiError(meta.errors.editsDisabled);
if (!Users.isLocalUser(user)) {
throw new ApiError(meta.errors.notLocalUser);
}

View file

@ -16,12 +16,24 @@
<template #label>
<i class="ph-pencil-line ph-bold ph-lg"></i>
{{ i18n.ts._experiments.enablePostEditing }}
<span class="_beta"> {{ i18n.ts.beta }}</span>
</template>
<template #caption>{{
i18n.ts._experiments.postEditingCaption
}}</template>
</FormSwitch>
<FormSwitch
v-model="enablePostImports"
@update:modelValue="save"
class="_formBlock"
>
<template #label>
<i class="ph-pencil-line ph-bold ph-lg"></i>
{{ i18n.ts._experiments.enablePostImports }}
</template>
<template #caption>{{
i18n.ts._experiments.postImportsCaption
}}</template>
</FormSwitch>
</FormSuspense>
</MkSpacer>
</MkStickyContainer>
@ -38,11 +50,13 @@ import { i18n } from "@/i18n";
import { definePageMetadata } from "@/scripts/page-metadata";
let enablePostEditing = $ref(false);
let enablePostImports = $ref(false);
let meta = $ref<MetaExperiments | null>(null);
type MetaExperiments = {
experimentalFeatures?: {
postEditing?: boolean;
postImports?: boolean;
};
};
@ -51,12 +65,14 @@ async function init() {
if (!meta) return;
enablePostEditing = meta.experimentalFeatures?.postEditing ?? false;
enablePostImports = meta.experimentalFeatures?.postImports ?? false;
}
function save() {
const experiments: MetaExperiments = {
experimentalFeatures: {
postEditing: enablePostEditing,
postImports: enablePostImports,
},
};
os.apiWithDialog("admin/update-meta", experiments).then(() => {