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: { postEditing: {
type: "boolean", type: "boolean",
}, },
postImports: {
type: "boolean",
},
}, },
}, },
}, },

View File

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

View File

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

View File

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

View File

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