Skip to content

Commit

Permalink
Pro 6468 big upload (#103)
Browse files Browse the repository at this point in the history
* sorts translation file, add one new key
* improves slightly import errors when no format found for a file type
* uses big-upload client and middleware
  • Loading branch information
ValJed authored Feb 5, 2025
1 parent c620785 commit 926e3d8
Show file tree
Hide file tree
Showing 12 changed files with 66 additions and 51 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## UNRELEASED

### Adds

* Adds a method to sort all exported documents, makes sure that parent pages come always first.
* Uses the new big-upload feature of apostrophe to allow very large export files to be imported.

## 2.6.0 (2025-01-27)

### Adds
Expand Down
9 changes: 5 additions & 4 deletions i18n/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
"exporting": "Exportiere {{ type }}...",
"import": "Importiere {{ type }}",
"importCleanFailed": "Die Bereinigung der importierten Datei auf dem Server ist fehlgeschlagen.",
"importWithCurrentLocaleHeading": "Andere Sprache erkannt",
"importWithCurrentLocaleDescription": "Diese Datei wurde aus der \"{{ docsLocale }}\"-Sprache exportiert. Sind Sie sicher, dass Sie sie in die \"{{ currentLocale }}\"-Sprache importieren möchten?",
"importDuplicateContinue": "Import fortsetzen",
"importDuplicateDetected": "Duplikate erkannt.",
"importDuplicateMessage": "Überprüfen Sie die Elemente, die Sie während des Imports überschreiben möchten.",
Expand All @@ -26,12 +24,15 @@
"importFileError": "Der Import der {{ format }}-Datei ist fehlgeschlagen",
"importModalDescription": "Das Importieren von Inhalten erfordert eine {{ formats }}-Datei. Siehe unsere <a href=\"https://github.com/apostrophecms/import-export\" target=\"_blank\">offizielle Dokumentation</a>.",
"importSucceed": "Import erfolgreich!",
"importWarning": "Das Importieren einer Apostrophe-Exportdatei auf einer inkompatiblen Website kann unvorhersehbar sein.",
"importWithCurrentLocaleDescription": "Diese Datei wurde aus der \"{{ docsLocale }}\"-Sprache exportiert. Sind Sie sicher, dass Sie sie in die \"{{ currentLocale }}\"-Sprache importieren möchten?",
"importWithCurrentLocaleHeading": "Andere Sprache erkannt",
"imported": "Importiert",
"importing": "Importiere {{ type }}...",
"importWarning": "Das Importieren einer Apostrophe-Exportdatei auf einer inkompatiblen Website kann unvorhersehbar sein.",
"lastEdited": "Zuletzt bearbeitet",
"or": "oder",
"title": "Titel",
"type": "Typ",
"typeUnknown": "Typ \"{{ type }}\" ist ungültig."
"typeUnknown": "Typ \"{{ type }}\" ist ungültig.",
"unsupportedFileType": "Der Dateityp {{ type }} wird nicht unterstützt."
}
11 changes: 6 additions & 5 deletions i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,25 @@
"exporting": "Exporting {{ type }}...",
"import": "Import {{ type }}",
"importCleanFailed": "The cleaning of the imported file on the server failed.",
"importWithCurrentLocaleHeading": "Different locale detected",
"importWithCurrentLocaleDescription": "This file was exported from the \"{{ docsLocale }}\" locale. Are you sure you want to import it into the \"{{ currentLocale }}\" locale?",
"importDraftsOnly": "Import all documents as drafts",
"importDraftsOnlyTooltip": "Content types that do not have separate drafts will be imported normally.",
"importDuplicateContinue": "Continue Import",
"importDuplicateDetected": "Duplicates Detected.",
"importDuplicateMessage": "Check the items you'd like to overwrite during import.",
"importFailed": "Import failed",
"importFailedForSome": "{{ count }} documents encountered error during import",
"importFileError": "The {{ format }} file import failed",
"importFileError": "The {{ type }} file import failed",
"importModalDescription": "Importing content requires a {{ formats }} file. See our <a href=\"https://github.com/apostrophecms/import-export\" target=\"_blank\">official documentation</a>.",
"importSucceed": "Import Succeed!",
"importWarning": "Importing an Apostrophe export file on an incompatible website may not behave as expected.",
"importWithCurrentLocaleDescription": "This file was exported from the \"{{ docsLocale }}\" locale. Are you sure you want to import it into the \"{{ currentLocale }}\" locale?",
"importWithCurrentLocaleHeading": "Different locale detected",
"imported": "Imported",
"importing": "Importing {{ type }}...",
"importWarning": "Importing an Apostrophe export file on an incompatible website may not behave as expected.",
"lastEdited": "Last edited",
"or": "or",
"title": "Title",
"type": "Type",
"typeUnknown": "Type \"{{ type }}\" is not valid."
"typeUnknown": "Type \"{{ type }}\" is not valid.",
"unsupportedFileType": "File type {{ type }} is not supported."
}
9 changes: 5 additions & 4 deletions i18n/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
"exporting": "Exportando {{ type }}...",
"import": "Importar {{ type }}",
"importCleanFailed": "La limpieza del archivo importado en el servidor falló.",
"importWithCurrentLocaleHeading": "Se detectó una configuración regional diferente",
"importWithCurrentLocaleDescription": "Este archivo fue exportado desde la configuración regional \"{{ docsLocale }}\". ¿Estás seguro de que deseas importarlo a la configuración regional \"{{ currentLocale }}\"?",
"importDuplicateContinue": "Continuar Importación",
"importDuplicateDetected": "Duplicados Detectados.",
"importDuplicateMessage": "Marca los elementos que te gustaría sobrescribir durante la importación.",
Expand All @@ -26,12 +24,15 @@
"importFileError": "La importación del archivo {{ format }} falló",
"importModalDescription": "Importar contenido requiere un archivo {{ formats }}. Consulta nuestra <a href=\"https://github.com/apostrophecms/import-export\" target=\"_blank\">documentación oficial</a>.",
"importSucceed": "Importación Exitosa!",
"importWarning": "Importar un archivo de exportación de Apostrophe en un sitio web incompatible puede no comportarse como se esperaba.",
"importWithCurrentLocaleDescription": "Este archivo fue exportado desde la configuración regional \"{{ docsLocale }}\". ¿Estás seguro de que deseas importarlo a la configuración regional \"{{ currentLocale }}\"?",
"importWithCurrentLocaleHeading": "Se detectó una configuración regional diferente",
"imported": "Importado",
"importing": "Importando {{ type }}...",
"importWarning": "Importar un archivo de exportación de Apostrophe en un sitio web incompatible puede no comportarse como se esperaba.",
"lastEdited": "Última edición",
"or": "o",
"title": "Título",
"type": "Tipo",
"typeUnknown": "Tipo \"{{ type }}\" no es válido."
"typeUnknown": "Tipo \"{{ type }}\" no es válido.",
"unsupportedFileType": "El tipo de archivo {{ type }} no es compatible."
}
9 changes: 5 additions & 4 deletions i18n/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
"exporting": "Exportation de {{ type }}...",
"import": "Importer {{ type }}",
"importCleanFailed": "Le nettoyage du fichier importé sur le serveur a échoué.",
"importWithCurrentLocaleHeading": "Locale différente détectée",
"importWithCurrentLocaleDescription": "Ce fichier a été exporté à partir de la locale \"{{ docsLocale }}\". Êtes-vous sûr de vouloir l'importer dans la locale \"{{ currentLocale }}\"?",
"importDuplicateContinue": "Continuer l'importation",
"importDuplicateDetected": "Doublons détectés.",
"importDuplicateMessage": "Cochez les éléments que vous souhaitez écraser lors de l'importation.",
Expand All @@ -26,12 +24,15 @@
"importFileError": "L'importation du fichier {{ format }} a échoué",
"importModalDescription": "L'importation de contenu nécessite un fichier {{ formats }}. Consultez notre <a href=\"https://github.com/apostrophecms/import-export\" target=\"_blank\">documentation officielle</a>.",
"importSucceed": "Importation réussie !",
"importWarning": "L'importation d'un fichier d'exportation Apostrophe sur un site Web incompatible peut ne pas se dérouler comme prévu.",
"importWithCurrentLocaleDescription": "Ce fichier a été exporté à partir de la locale \"{{ docsLocale }}\". Êtes-vous sûr de vouloir l'importer dans la locale \"{{ currentLocale }}\"?",
"importWithCurrentLocaleHeading": "Locale différente détectée",
"imported": "Importé",
"importing": "Importation de {{ type }}...",
"importWarning": "L'importation d'un fichier d'exportation Apostrophe sur un site Web incompatible peut ne pas se dérouler comme prévu.",
"lastEdited": "Dernière modification",
"or": "ou",
"title": "Titre",
"type": "Type",
"typeUnknown": "Type \"{{ type }}\" n'est pas valide."
"typeUnknown": "Type \"{{ type }}\" n'est pas valide.",
"unsupportedFileType": "Le type de fichier {{ type }} n'est pas supporté."
}
9 changes: 5 additions & 4 deletions i18n/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
"exporting": "Esportazione {{ type }}...",
"import": "Importa {{ type }}",
"importCleanFailed": "La pulizia del file importato sul server è fallita.",
"importWithCurrentLocaleHeading": "Locale diverso rilevato",
"importWithCurrentLocaleDescription": "Questo file è stato esportato dalla locale \"{{ docsLocale }}\". Sei sicuro di volerlo importare nella locale \"{{ currentLocale }}\"?",
"importDuplicateContinue": "Continua importazione",
"importDuplicateDetected": "Duplicati rilevati.",
"importDuplicateMessage": "Controlla gli elementi che desideri sovrascrivere durante l'importazione.",
Expand All @@ -26,12 +24,15 @@
"importFileError": "L'importazione del file {{ format }} è fallita",
"importModalDescription": "L'importazione di contenuti richiede un file {{ formats }}. Consulta la nostra <a href=\"https://github.com/apostrophecms/import-export\" target=\"_blank\">documentazione ufficiale</a>.",
"importSucceed": "Importazione riuscita!",
"importWarning": "Importare un file di esportazione di Apostrophe su un sito web incompatibile potrebbe non comportarsi come previsto.",
"importWithCurrentLocaleDescription": "Questo file è stato esportato dalla locale \"{{ docsLocale }}\". Sei sicuro di volerlo importare nella locale \"{{ currentLocale }}\"?",
"importWithCurrentLocaleHeading": "Locale diverso rilevato",
"imported": "Importato",
"importing": "Importazione {{ type }}...",
"importWarning": "Importare un file di esportazione di Apostrophe su un sito web incompatibile potrebbe non comportarsi come previsto.",
"lastEdited": "Ultima modifica",
"or": "o",
"title": "Titolo",
"type": "Tipo",
"typeUnknown": "Tipo \"{{ type }}\" non valido."
"typeUnknown": "Tipo \"{{ type }}\" non valido.",
"unsupportedFileType": "Il tipo di file {{tipo }} non è supportato."
}
9 changes: 5 additions & 4 deletions i18n/pt-BR.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
"exporting": "Exportando {{ type }}...",
"import": "Importar {{ type }}",
"importCleanFailed": "A limpeza do arquivo importado no servidor falhou.",
"importWithCurrentLocaleHeading": "Localidade diferente detectada",
"importWithCurrentLocaleDescription": "Este arquivo foi exportado da localidade \"{{ docsLocale }}\". Você tem certeza de que deseja importá-lo para a localidade \"{{ currentLocale }}\"?",
"importDuplicateContinue": "Continuar Importação",
"importDuplicateDetected": "Duplicatas Detectadas.",
"importDuplicateMessage": "Marque os itens que você deseja sobrescrever durante a importação.",
Expand All @@ -26,12 +24,15 @@
"importFileError": "A importação do arquivo {{ format }} falhou",
"importModalDescription": "Importar conteúdo requer um arquivo {{ formats }}. Veja nossa <a href=\"https://github.com/apostrophecms/import-export\" target=\"_blank\">documentação oficial</a>.",
"importSucceed": "Importação bem-sucedida!",
"importWarning": "Importar um arquivo de exportação do Apostrophe em um site incompatível pode não funcionar como esperado.",
"importWithCurrentLocaleDescription": "Este arquivo foi exportado da localidade \"{{ docsLocale }}\". Você tem certeza de que deseja importá-lo para a localidade \"{{ currentLocale }}\"?",
"importWithCurrentLocaleHeading": "Localidade diferente detectada",
"imported": "Importado",
"importing": "Importando {{ type }}...",
"importWarning": "Importar um arquivo de exportação do Apostrophe em um site incompatível pode não funcionar como esperado.",
"lastEdited": "Última edição",
"or": "ou",
"title": "Título",
"type": "Tipo",
"typeUnknown": "Tipo \"{{ type }}\" não é válido."
"typeUnknown": "Tipo \"{{ type }}\" não é válido.",
"unsupportedFileType": "Não há suporte para o tipo de arquivo {{ type }}."
}
9 changes: 5 additions & 4 deletions i18n/sk.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
"exporting": "Exportovanie {{ type }}...",
"import": "Importovať {{ type }}",
"importCleanFailed": "Údržba importovaného súboru na serveri zlyhala.",
"importWithCurrentLocaleHeading": "Zistený iný jazyk",
"importWithCurrentLocaleDescription": "Tento súbor bol exportovaný z jazyka \"{{ docsLocale }}\". Ste si istí, že ho chcete importovať do jazyka \"{{ currentLocale }}\"?",
"importDuplicateContinue": "Pokračovať v importe",
"importDuplicateDetected": "Zistené duplicity.",
"importDuplicateMessage": "Skontrolujte položky, ktoré chcete pri importe prepísať.",
Expand All @@ -26,12 +24,15 @@
"importFileError": "Import súboru {{ format }} zlyhal",
"importModalDescription": "Import obsahu vyžaduje súbor {{ formats }}. Pozrite si našu <a href=\"https://github.com/apostrophecms/import-export\" target=\"_blank\">oficiálnu dokumentáciu</a>.",
"importSucceed": "Import úspešný!",
"importWarning": "Importovanie exportného súboru Apostrophe na nekompatibilnej webovej stránke nemusí fungovať, ako sa očakáva.",
"importWithCurrentLocaleDescription": "Tento súbor bol exportovaný z jazyka \"{{ docsLocale }}\". Ste si istí, že ho chcete importovať do jazyka \"{{ currentLocale }}\"?",
"importWithCurrentLocaleHeading": "Zistený iný jazyk",
"imported": "Importované",
"importing": "Importovanie {{ type }}...",
"importWarning": "Importovanie exportného súboru Apostrophe na nekompatibilnej webovej stránke nemusí fungovať, ako sa očakáva.",
"lastEdited": "Nap posledne editované",
"or": "alebo",
"title": "Názov",
"type": "Typ",
"typeUnknown": "Typ \"{{ type }}\" nie je platný."
"typeUnknown": "Typ \"{{ type }}\" nie je platný.",
"unsupportedFileType": "Typ súboru {{ type }} nie je podporovaný."
}
9 changes: 6 additions & 3 deletions lib/methods/import.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ module.exports = self => {
if (!req.user) {
throw self.apos.error('forbidden');
}

const { file } = req.files || {};
const importDraftsOnly = self.apos.launder.boolean(req.body.importDraftsOnly);
const overrideLocale = self.apos.launder.boolean(req.body.overrideLocale);
Expand Down Expand Up @@ -51,8 +50,12 @@ module.exports = self => {
await self.setExportPathId(exportPath);
}
} catch (error) {
await self.apos.notify(req, 'aposImportExport:importFileError', {
interpolate: { format: format?.label },
const [ errKey, type ] = !format && (file?.type || formatLabel)
? [ 'aposImportExport:unsupportedFileType', file?.type || formatLabel ]
: [ 'aposImportExport:importFileError', format?.label ];

await self.apos.notify(req, errKey, {
interpolate: { type },
dismiss: true,
icon: 'alert-circle-icon',
type: 'danger'
Expand Down
10 changes: 5 additions & 5 deletions modules/@apostrophecms/import-export-page/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
const multiparty = require('connect-multiparty');

module.exports = {
improve: '@apostrophecms/page',

Expand Down Expand Up @@ -52,9 +50,10 @@ module.exports = {
post: {
...self.options.importExport?.import !== false && {
importExportImport: [
multiparty(),
self.apos.http.bigUploadMiddleware(),
async (req) => {
return self.apos.modules['@apostrophecms/import-export'].import(req, self.__meta.name);
return self.apos.modules['@apostrophecms/import-export']
.import(req, self.__meta.name);
}
]
},
Expand All @@ -63,7 +62,8 @@ module.exports = {
// Add the page label to req.body for notifications.
req.body.type = req.t('apostrophe:page');

return self.apos.modules['@apostrophecms/import-export'].export(req, self);
return self.apos.modules['@apostrophecms/import-export']
.export(req, self);
}
},
importExportExportBatch(req) {
Expand Down
7 changes: 3 additions & 4 deletions modules/@apostrophecms/import-export-piece-type/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
const multiparty = require('connect-multiparty');

module.exports = {
improve: '@apostrophecms/piece-type',
cascades: [ 'batchOperations' ],
Expand Down Expand Up @@ -52,9 +50,10 @@ module.exports = {
post: {
...self.options.importExport?.import !== false && {
importExportImport: [
multiparty(),
self.apos.http.bigUploadMiddleware(),
async (req) => {
return self.apos.modules['@apostrophecms/import-export'].import(req, self.__meta.name);
return self.apos.modules['@apostrophecms/import-export']
.import(req, self.__meta.name);
}
]
},
Expand Down
19 changes: 9 additions & 10 deletions ui/apos/components/AposImportModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@
</template>

<script>
import bigUpload from 'Modules/@apostrophecms/http/big-upload-client.js';
export default {
props: {
// The Manager context menu items send moduleAction
Expand Down Expand Up @@ -174,18 +176,15 @@ export default {
});
return;
}
const formData = new FormData();
formData.append('file', this.selectedFile);
formData.append('importDraftsOnly', this.checked.includes('importDraftsOnly'));
apos.bus.$emit('import-export-import-started');
apos.http.post(`${this.universalModuleAction}/${this.action}`, {
body: formData
bigUpload(`${this.universalModuleAction}/${this.action}`, {
files: {
file: this.selectedFile
},
body: {
importDraftsOnly: this.checked.includes('importDraftsOnly')
}
}).catch(() => {
apos.notify('aposImportExport:importFailed', {
type: 'danger',
dismiss: true
});
apos.bus.$emit('import-export-import-ended');
});
Expand Down

0 comments on commit 926e3d8

Please sign in to comment.