Skip to content

Commit

Permalink
Fix file deletion, sort by date in dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
xirreal committed Jan 3, 2025
1 parent 908494b commit 95a7b8b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
2 changes: 1 addition & 1 deletion plugins/externalUpload/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export const settings = () => (
"CORSRules": [
{
"AllowedHeaders": ["*"],
"AllowedMethods": ["GET", "PUT"],
"AllowedMethods": ["GET", "PUT", "DELETE"],
"AllowedOrigins": ["*"],
"ExposeHeaders": ["ETag"]
}
Expand Down
6 changes: 3 additions & 3 deletions plugins/externalUpload/modal.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import styles from "./modal.jsx.scss";
import { formatFileSize, getAllFiles, getFilePreview, uploadFiles, formatDate, getUrl } from "./utils";
import { formatFileSize, getAllFiles, getFilePreview, uploadFiles, formatDate, getUrl, deleteFile } from "./utils";

const {
ui: {
Expand Down Expand Up @@ -132,7 +132,7 @@ export function UploadModal(closeModal) {
};

const handleDeleteFile = async (file) => {
console.log("Deleting file:", file);
await deleteFile(file.Key);
await fetchDashboardFiles();
};

Expand Down Expand Up @@ -289,7 +289,7 @@ export function UploadModal(closeModal) {
<Button
disabled={isUploading() || files().length === 0}
size={ButtonSizes.MEDIUM}
color={ButtonColors.BRANDED}
color={ButtonColors.BRAND}
onClick={handleConfirm}
>
{isUploading() ? "Uploading..." : "Upload"}
Expand Down
13 changes: 11 additions & 2 deletions plugins/externalUpload/utils.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { S3Client, ListObjectsV2Command } from "@aws-sdk/client-s3";
import { S3Client, ListObjectsV2Command, DeleteObjectCommand } from "@aws-sdk/client-s3";
import { Upload } from "@aws-sdk/lib-storage";
import xxhash from "xxhash-wasm";

Expand Down Expand Up @@ -125,7 +125,16 @@ export async function getAllFiles() {
}),
);

return response.Contents;
return response.Contents.sort((a, b) => b.LastModified - a.LastModified);
}

export async function deleteFile(key) {
await s3Client.send(
new DeleteObjectCommand({
Bucket: BUCKET_NAME,
Key: key,
}),
);
}

export function formatDate(date) {
Expand Down

0 comments on commit 95a7b8b

Please sign in to comment.