add: Importing of Posts

- Supports Instagram, Mastodon/Pleroma/Akkoma, Twitter and *key
This commit is contained in:
Mar0xy 2023-11-12 15:07:32 +01:00 committed by Marie
parent 4f0e0f067e
commit 83f328de8a
18 changed files with 971 additions and 6 deletions

View file

@ -112,6 +112,7 @@ export const ROLE_POLICIES = [
'gtlAvailable',
'ltlAvailable',
'canPublicNote',
'canImportNotes',
'canInvite',
'inviteLimit',
'inviteLimitCycle',

View file

@ -160,6 +160,26 @@ SPDX-License-Identifier: AGPL-3.0-only
</div>
</MkFolder>
<MkFolder v-if="matchQuery([i18n.ts._role._options.canImportNotes, 'canImportNotes'])">
<template #label>{{ i18n.ts._role._options.canImportNotes }}</template>
<template #suffix>
<span v-if="role.policies.canImportNotes.useDefault" :class="$style.useDefaultLabel">{{ i18n.ts._role.useBaseValue }}</span>
<span v-else>{{ role.policies.canImportNotes.value ? i18n.ts.yes : i18n.ts.no }}</span>
<span :class="$style.priorityIndicator"><i :class="getPriorityIcon(role.policies.canImportNotes)"></i></span>
</template>
<div class="_gaps">
<MkSwitch v-model="role.policies.canImportNotes.useDefault" :readonly="readonly">
<template #label>{{ i18n.ts._role.useBaseValue }}</template>
</MkSwitch>
<MkSwitch v-model="role.policies.canImportNotes.value" :disabled="role.policies.canImportNotes.useDefault" :readonly="readonly">
<template #label>{{ i18n.ts.enable }}</template>
</MkSwitch>
<MkRange v-model="role.policies.canImportNotes.priority" :min="0" :max="2" :step="1" easing :textConverter="(v) => v === 0 ? i18n.ts._role._priority.low : v === 1 ? i18n.ts._role._priority.middle : v === 2 ? i18n.ts._role._priority.high : ''">
<template #label>{{ i18n.ts._role.priority }}</template>
</MkRange>
</div>
</MkFolder>
<MkFolder v-if="matchQuery([i18n.ts._role._options.canInvite, 'canInvite'])">
<template #label>{{ i18n.ts._role._options.canInvite }}</template>
<template #suffix>

View file

@ -48,6 +48,14 @@ SPDX-License-Identifier: AGPL-3.0-only
</MkSwitch>
</MkFolder>
<MkFolder v-if="matchQuery([i18n.ts._role._options.canImportNotes, 'canImportNotes'])">
<template #label>{{ i18n.ts._role._options.canImportNotes }}</template>
<template #suffix>{{ policies.canImportNotes ? i18n.ts.yes : i18n.ts.no }}</template>
<MkSwitch v-model="policies.canImportNotes">
<template #label>{{ i18n.ts.enable }}</template>
</MkSwitch>
</MkFolder>
<MkFolder v-if="matchQuery([i18n.ts._role._options.canInvite, 'canInvite'])">
<template #label>{{ i18n.ts._role._options.canInvite }}</template>
<template #suffix>{{ policies.canInvite ? i18n.ts.yes : i18n.ts.no }}</template>

View file

@ -7,11 +7,25 @@ SPDX-License-Identifier: AGPL-3.0-only
<div class="_gaps_m">
<FormSection first>
<template #label><i class="ph-pencil ph-bold ph-lg"></i> {{ i18n.ts._exportOrImport.allNotes }}</template>
<MkFolder>
<template #label>{{ i18n.ts.export }}</template>
<template #icon><i class="ph-download ph-bold ph-lg"></i></template>
<MkButton primary :class="$style.button" inline @click="exportNotes()"><i class="ph-download ph-bold ph-lg"></i> {{ i18n.ts.export }}</MkButton>
</MkFolder>
<div class="_gaps_s">
<MkFolder>
<template #label>{{ i18n.ts.export }}</template>
<template #icon><i class="ph-download ph-bold ph-lg"></i></template>
<MkButton primary :class="$style.button" inline @click="exportNotes()"><i class="ph-download ph-bold ph-lg"></i> {{ i18n.ts.export }}</MkButton>
</MkFolder>
<MkFolder v-if="$i && $i.policies.canImportNotes">
<template #label>{{ i18n.ts.import }}</template>
<template #icon><i class="ph-upload ph-bold ph-lg"></i></template>
<MkRadios v-model="noteType" style="padding-bottom: 8px;" small>
<template #label>Origin</template>
<option value="Misskey">Misskey/Firefish</option>
<option value="Mastodon">Mastodon/Pleroma/Akkoma</option>
<option value="Twitter">Twitter</option>
<option value="Instagram">Instagram</option>
</MkRadios>
<MkButton primary :class="$style.button" inline @click="importNotes($event)"><i class="ph-upload ph-bold ph-lg"></i> {{ i18n.ts.import }}</MkButton>
</MkFolder>
</div>
</FormSection>
<FormSection>
<template #label><i class="ph-star ph-bold ph-lg"></i> {{ i18n.ts._exportOrImport.favoritedNotes }}</template>
@ -116,6 +130,7 @@ import MkButton from '@/components/MkButton.vue';
import FormSection from '@/components/form/section.vue';
import MkFolder from '@/components/MkFolder.vue';
import MkSwitch from '@/components/MkSwitch.vue';
import MkRadios from '@/components/MkRadios.vue';
import * as os from '@/os.js';
import { selectFile } from '@/scripts/select-file.js';
import { i18n } from '@/i18n.js';
@ -125,6 +140,7 @@ import { defaultStore } from "@/store.js";
const excludeMutingUsers = ref(false);
const excludeInactiveUsers = ref(false);
const noteType = ref(null);
const withReplies = ref(defaultStore.state.defaultWithReplies);
const onExportSuccess = () => {
@ -188,6 +204,14 @@ const importFollowing = async (ev) => {
}).then(onImportSuccess).catch(onError);
};
const importNotes = async (ev) => {
const file = await selectFile(ev.currentTarget ?? ev.target);
os.api('i/import-notes', {
fileId: file.id,
type: noteType.value,
}).then(onImportSuccess).catch(onError);
};
const importUserLists = async (ev) => {
const file = await selectFile(ev.currentTarget ?? ev.target);
os.api('i/import-user-lists', { fileId: file.id }).then(onImportSuccess).catch(onError);