feat: Import improvements (#3064)
* feat: Split and simplify import/export pages in prep for more options * minor fixes * File operations for imports * test * icons
This commit is contained in:
@@ -19,60 +19,62 @@ export default class ExportsProcessor {
|
||||
const user = await User.findByPk(actorId);
|
||||
invariant(user, "user operation not found");
|
||||
|
||||
const exportData = await FileOperation.findByPk(event.modelId);
|
||||
invariant(exportData, "exportData not found");
|
||||
const fileOperation = await FileOperation.findByPk(event.modelId);
|
||||
invariant(fileOperation, "fileOperation not found");
|
||||
|
||||
const collectionIds =
|
||||
// @ts-expect-error ts-migrate(2339) FIXME: Property 'collectionId' does not exist on type 'Co... Remove this comment to see the full error message
|
||||
event.collectionId || (await user.collectionIds());
|
||||
"collectionId" in event
|
||||
? event.collectionId
|
||||
: await user.collectionIds();
|
||||
const collections = await Collection.findAll({
|
||||
where: {
|
||||
id: collectionIds,
|
||||
},
|
||||
});
|
||||
this.updateFileOperation(exportData, actorId, teamId, {
|
||||
this.updateFileOperation(fileOperation, actorId, teamId, {
|
||||
state: "creating",
|
||||
});
|
||||
// heavy lifting of creating the zip file
|
||||
Logger.info(
|
||||
"processor",
|
||||
`Archiving collections for file operation ${exportData.id}`
|
||||
`Archiving collections for file operation ${fileOperation.id}`
|
||||
);
|
||||
const filePath = await archiveCollections(collections);
|
||||
let url, state;
|
||||
let url;
|
||||
let state: any = "creating";
|
||||
|
||||
try {
|
||||
// @ts-expect-error ts-migrate(2769) FIXME: No overload matches this call.
|
||||
const readBuffer = await fs.promises.readFile(filePath);
|
||||
// @ts-expect-error ts-migrate(2769) FIXME: No overload matches this call.
|
||||
const stat = await fs.promises.stat(filePath);
|
||||
this.updateFileOperation(exportData, actorId, teamId, {
|
||||
this.updateFileOperation(fileOperation, actorId, teamId, {
|
||||
state: "uploading",
|
||||
size: stat.size,
|
||||
});
|
||||
Logger.info(
|
||||
"processor",
|
||||
`Uploading archive for file operation ${exportData.id}`
|
||||
`Uploading archive for file operation ${fileOperation.id}`
|
||||
);
|
||||
url = await uploadToS3FromBuffer(
|
||||
readBuffer,
|
||||
"application/zip",
|
||||
exportData.key,
|
||||
fileOperation.key,
|
||||
"private"
|
||||
);
|
||||
Logger.info(
|
||||
"processor",
|
||||
`Upload complete for file operation ${exportData.id}`
|
||||
`Upload complete for file operation ${fileOperation.id}`
|
||||
);
|
||||
state = "complete";
|
||||
} catch (error) {
|
||||
Logger.error("Error exporting collection data", error, {
|
||||
fileOperationId: exportData.id,
|
||||
fileOperationId: fileOperation.id,
|
||||
});
|
||||
state = "error";
|
||||
url = null;
|
||||
url = undefined;
|
||||
} finally {
|
||||
this.updateFileOperation(exportData, actorId, teamId, {
|
||||
this.updateFileOperation(fileOperation, actorId, teamId, {
|
||||
state,
|
||||
url,
|
||||
});
|
||||
@@ -85,7 +87,7 @@ export default class ExportsProcessor {
|
||||
} else {
|
||||
mailer.sendTemplate("exportSuccess", {
|
||||
to: user.email,
|
||||
id: exportData.id,
|
||||
id: fileOperation.id,
|
||||
teamUrl: team.url,
|
||||
});
|
||||
}
|
||||
@@ -101,15 +103,14 @@ export default class ExportsProcessor {
|
||||
fileOperation: FileOperation,
|
||||
actorId: string,
|
||||
teamId: string,
|
||||
data: Record<string, any>
|
||||
data: Partial<FileOperation>
|
||||
) {
|
||||
await fileOperation.update(data);
|
||||
await Event.add({
|
||||
name: "fileOperations.update",
|
||||
teamId,
|
||||
actorId,
|
||||
// @ts-expect-error dataValues exists
|
||||
data: fileOperation.dataValues,
|
||||
modelId: fileOperation.id,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user