nicolium: archive imports

Signed-off-by: nicole mikołajczyk <git@mkljczk.pl>
This commit is contained in:
nicole mikołajczyk
2026-02-15 16:52:08 +01:00
parent c17561a561
commit 4cf4c0e11b
5 changed files with 48 additions and 3 deletions

View File

@@ -966,6 +966,8 @@ const getFeatures = (instance: Instance) => {
v.software === PLEROMA,
]),
importArchive: false,
/**
* Import a .csv file with a list of blocked users.
* @see POST /api/pleroma/blocks_import

View File

@@ -98,6 +98,7 @@
"lodash-es": "^4.17.23",
"mini-css-extract-plugin": "^2.9.4",
"mutative": "^1.3.0",
"object-to-formdata": "^4.5.1",
"path-browserify": "^1.0.1",
"pl-api": "workspace:*",
"postcss": "^8.5.3",

View File

@@ -1072,16 +1072,20 @@
"icon_button.icons": "Icons",
"icon_button.label": "Select icon",
"import_data.actions.import": "Import",
"import_data.actions.import_archive": "Import archive",
"import_data.actions.import_blocks": "Import blocks",
"import_data.actions.import_follows": "Import follows",
"import_data.actions.import_mutes": "Import mutes",
"import_data.archive_label": "Archive",
"import_data.blocks_label": "Blocks",
"import_data.follows_label": "Follows",
"import_data.hints.archive": "Archive containing an archive of statuses",
"import_data.hints.blocks": "CSV file containing a list of blocked accounts",
"import_data.hints.follows": "CSV file containing a list of followed accounts",
"import_data.hints.mutes": "CSV file containing a list of muted accounts",
"import_data.mutes_label": "Mutes",
"import_data.overwrite": "Overwrite instead of appending",
"import_data.success.archive": "Archive imported successfully",
"import_data.success.blocks": "Blocks imported successfully",
"import_data.success.followers": "Followers imported successfully",
"import_data.success.mutes": "Mutes imported successfully",

View File

@@ -1,3 +1,4 @@
import { serialize } from 'object-to-formdata';
import React, { useState } from 'react';
import { defineMessages, FormattedMessage, useIntl, type MessageDescriptor } from 'react-intl';
@@ -26,6 +27,10 @@ const messages = defineMessages({
defaultMessage: 'Followers imported successfully',
},
mutesSuccess: { id: 'import_data.success.mutes', defaultMessage: 'Mutes imported successfully' },
archiveSuccess: {
id: 'import_data.success.archive',
defaultMessage: 'Archive imported successfully',
},
});
const followMessages = defineMessages({
@@ -55,6 +60,15 @@ const muteMessages = defineMessages({
submit: { id: 'import_data.actions.import_mutes', defaultMessage: 'Import mutes' },
});
const archiveMessages = defineMessages({
input_label: { id: 'import_data.archive_label', defaultMessage: 'Archive' },
input_hint: {
id: 'import_data.hints.archive',
defaultMessage: 'Archive containing an archive of statuses',
},
submit: { id: 'import_data.actions.import_archive', defaultMessage: 'Import archive' },
});
interface IDataImporter {
messages: {
input_label: MessageDescriptor;
@@ -140,20 +154,34 @@ const ImportDataPage = () => {
const features = useFeatures();
const importFollows = (list: File | string, overwrite?: boolean) =>
client.settings.importFollows(list, overwrite ? 'overwrite' : 'merge').then((response) => {
client.settings.importFollows(list, overwrite ? 'overwrite' : 'merge').then(() => {
toast.success(messages.followersSuccess);
});
const importBlocks = (list: File | string, overwrite?: boolean) =>
client.settings.importBlocks(list, overwrite ? 'overwrite' : 'merge').then((response) => {
client.settings.importBlocks(list, overwrite ? 'overwrite' : 'merge').then(() => {
toast.success(messages.blocksSuccess);
});
const importMutes = (list: File | string) =>
client.settings.importMutes(list).then((response) => {
client.settings.importMutes(list).then(() => {
toast.success(messages.mutesSuccess);
});
const importArchive = (file: File) => {
const form = serialize({ file, keep_unlisted: true }, { indices: true });
return client
.request('/api/pleroma/archive_import', {
method: 'POST',
body: form,
contentType: '',
})
.then(() => {
toast.success(messages.archiveSuccess);
});
};
return (
<Column label={intl.formatMessage(messages.heading)}>
{features.importFollows && (
@@ -177,6 +205,13 @@ const ImportDataPage = () => {
allowOverwrite={features.importOverwrite}
/>
)}
{features.importArchive && (
<DataImporter
action={importArchive}
messages={archiveMessages}
accept='.tar,.tar.gz,.zip'
/>
)}
</Column>
);
};

3
pnpm-lock.yaml generated
View File

@@ -295,6 +295,9 @@ importers:
mutative:
specifier: ^1.3.0
version: 1.3.0
object-to-formdata:
specifier: ^4.5.1
version: 4.5.1
path-browserify:
specifier: ^1.0.1
version: 1.0.1