Seth commited on
Commit
3131fa3
·
1 Parent(s): 36b5a20
Files changed (1) hide show
  1. frontend/src/pages/Repository.jsx +42 -38
frontend/src/pages/Repository.jsx CHANGED
@@ -192,7 +192,9 @@ export default function Repository() {
192
  const handleDeleteAsset = async (assetId) => {
193
  setIsDeleting(true);
194
  try {
195
- const response = await fetch(`/api/assets/${assetId}`, {
 
 
196
  method: 'DELETE',
197
  });
198
 
@@ -228,7 +230,9 @@ export default function Repository() {
228
  setIsLoadingPdf(true);
229
  setPdfPages(null);
230
  try {
231
- const response = await fetch(`/api/assets/${assetId}/pdf-pages`);
 
 
232
  if (response.ok) {
233
  const data = await response.json();
234
  setPdfPages(data);
@@ -855,7 +859,7 @@ export default function Repository() {
855
  className="h-9 w-9"
856
  onClick={(e) => {
857
  e.stopPropagation();
858
- window.open(`/api/assets/${asset.id}/download`, '_blank');
859
  }}
860
  >
861
  <Download className="w-4 h-4" />
@@ -888,7 +892,7 @@ export default function Repository() {
888
  setPreviewDialogOpen(true);
889
  // Load PDF pages if it's a PDF
890
  if (asset.type === 'document' && asset.name.toLowerCase().endsWith('.pdf')) {
891
- await loadPdfPages(asset.id);
892
  } else {
893
  setPdfPages(null);
894
  }
@@ -896,7 +900,7 @@ export default function Repository() {
896
  <Eye className="w-4 h-4 mr-2" /> Preview
897
  </DropdownMenuItem>
898
  <DropdownMenuItem onClick={() => {
899
- window.open(`/api/assets/${asset.id}/download`, '_blank');
900
  }}>
901
  <Download className="w-4 h-4 mr-2" /> Download
902
  </DropdownMenuItem>
@@ -904,7 +908,7 @@ export default function Repository() {
904
  className="text-red-600"
905
  onClick={async () => {
906
  if (confirm(`Are you sure you want to delete "${asset.name}"?`)) {
907
- await handleDeleteAsset(asset.id);
908
  }
909
  }}
910
  >
@@ -968,31 +972,31 @@ export default function Repository() {
968
  </Button>
969
  </DropdownMenuTrigger>
970
  <DropdownMenuContent align="end">
971
- <DropdownMenuItem onClick={async () => {
972
- setPreviewAsset(asset);
973
- setPreviewDialogOpen(true);
974
- // Load PDF pages if it's a PDF
975
- if (asset.type === 'document' && asset.name.toLowerCase().endsWith('.pdf')) {
976
- await loadPdfPages(asset.id);
977
- } else {
978
- setPdfPages(null);
979
- }
980
- }}>
981
- <Eye className="w-4 h-4 mr-2" /> Preview
982
- </DropdownMenuItem>
983
- <DropdownMenuItem onClick={() => {
984
- window.open(`/api/assets/${asset.id}/download`, '_blank');
985
- }}>
986
- <Download className="w-4 h-4 mr-2" /> Download
987
- </DropdownMenuItem>
988
- <DropdownMenuItem
989
- className="text-red-600"
990
- onClick={async () => {
991
- if (confirm(`Are you sure you want to delete "${asset.name}"?`)) {
992
- await handleDeleteAsset(asset.id);
993
  }
994
- }}
995
- >
 
 
 
 
 
 
 
 
 
 
 
 
 
 
996
  <Trash2 className="w-4 h-4 mr-2" /> Delete
997
  </DropdownMenuItem>
998
  </DropdownMenuContent>
@@ -1026,7 +1030,7 @@ export default function Repository() {
1026
  className="h-8 w-8 text-red-600 hover:text-red-700 hover:bg-red-50"
1027
  onClick={async () => {
1028
  if (confirm(`Are you sure you want to delete "${previewAsset.name}"?`)) {
1029
- await handleDeleteAsset(previewAsset.id);
1030
  }
1031
  }}
1032
  disabled={isDeleting}
@@ -1041,13 +1045,13 @@ export default function Repository() {
1041
  <div className="space-y-4">
1042
  {previewAsset.type === 'image' ? (
1043
  <img
1044
- src={`/api/assets/${previewAsset.id}/download`}
1045
  alt={previewAsset.name}
1046
  className="max-w-full h-auto rounded-lg mx-auto"
1047
  />
1048
  ) : previewAsset.type === 'video' ? (
1049
  <video
1050
- src={`/api/assets/${previewAsset.id}/download`}
1051
  controls
1052
  className="max-w-full rounded-lg mx-auto"
1053
  >
@@ -1069,7 +1073,7 @@ export default function Repository() {
1069
  This might be because poppler-utils is not installed. PDFs can still be downloaded.
1070
  </p>
1071
  <Button
1072
- onClick={() => window.open(`/api/assets/${previewAsset.id}/download`, '_blank')}
1073
  variant="outline"
1074
  className="border-red-200 text-red-600 hover:bg-red-100"
1075
  >
@@ -1103,7 +1107,7 @@ export default function Repository() {
1103
  <FileText className="w-16 h-16 text-slate-400 mb-4" />
1104
  <p className="text-slate-600 mb-4">Failed to load PDF preview</p>
1105
  <Button
1106
- onClick={() => window.open(`/api/assets/${previewAsset.id}/download`, '_blank')}
1107
  variant="outline"
1108
  >
1109
  <Download className="w-4 h-4 mr-2" />
@@ -1117,7 +1121,7 @@ export default function Repository() {
1117
  <FileText className="w-16 h-16 text-slate-400 mb-4" />
1118
  <p className="text-slate-600 mb-4">Preview not available for this file type</p>
1119
  <Button
1120
- onClick={() => window.open(`/api/assets/${previewAsset.id}/download`, '_blank')}
1121
  variant="outline"
1122
  >
1123
  <Download className="w-4 h-4 mr-2" />
@@ -1133,7 +1137,7 @@ export default function Repository() {
1133
  </div>
1134
  <div className="flex gap-2">
1135
  <Button
1136
- onClick={() => window.open(`/api/assets/${previewAsset.id}/download`, '_blank')}
1137
  variant="outline"
1138
  >
1139
  <Download className="w-4 h-4 mr-2" />
@@ -1144,7 +1148,7 @@ export default function Repository() {
1144
  className="text-red-600 border-red-200 hover:bg-red-50"
1145
  onClick={async () => {
1146
  if (confirm(`Are you sure you want to delete "${previewAsset.name}"?`)) {
1147
- await handleDeleteAsset(previewAsset.id);
1148
  }
1149
  }}
1150
  disabled={isDeleting}
 
192
  const handleDeleteAsset = async (assetId) => {
193
  setIsDeleting(true);
194
  try {
195
+ // Ensure assetId is a string to preserve precision
196
+ const assetIdStr = String(assetId);
197
+ const response = await fetch(`/api/assets/${assetIdStr}`, {
198
  method: 'DELETE',
199
  });
200
 
 
230
  setIsLoadingPdf(true);
231
  setPdfPages(null);
232
  try {
233
+ // Ensure assetId is a string to preserve precision
234
+ const assetIdStr = String(assetId);
235
+ const response = await fetch(`/api/assets/${assetIdStr}/pdf-pages`);
236
  if (response.ok) {
237
  const data = await response.json();
238
  setPdfPages(data);
 
859
  className="h-9 w-9"
860
  onClick={(e) => {
861
  e.stopPropagation();
862
+ window.open(`/api/assets/${String(asset.id)}/download`, '_blank');
863
  }}
864
  >
865
  <Download className="w-4 h-4" />
 
892
  setPreviewDialogOpen(true);
893
  // Load PDF pages if it's a PDF
894
  if (asset.type === 'document' && asset.name.toLowerCase().endsWith('.pdf')) {
895
+ await loadPdfPages(String(asset.id));
896
  } else {
897
  setPdfPages(null);
898
  }
 
900
  <Eye className="w-4 h-4 mr-2" /> Preview
901
  </DropdownMenuItem>
902
  <DropdownMenuItem onClick={() => {
903
+ window.open(`/api/assets/${String(asset.id)}/download`, '_blank');
904
  }}>
905
  <Download className="w-4 h-4 mr-2" /> Download
906
  </DropdownMenuItem>
 
908
  className="text-red-600"
909
  onClick={async () => {
910
  if (confirm(`Are you sure you want to delete "${asset.name}"?`)) {
911
+ await handleDeleteAsset(String(asset.id));
912
  }
913
  }}
914
  >
 
972
  </Button>
973
  </DropdownMenuTrigger>
974
  <DropdownMenuContent align="end">
975
+ <DropdownMenuItem onClick={async () => {
976
+ setPreviewAsset(asset);
977
+ setPreviewDialogOpen(true);
978
+ // Load PDF pages if it's a PDF
979
+ if (asset.type === 'document' && asset.name.toLowerCase().endsWith('.pdf')) {
980
+ await loadPdfPages(String(asset.id));
981
+ } else {
982
+ setPdfPages(null);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
983
  }
984
+ }}>
985
+ <Eye className="w-4 h-4 mr-2" /> Preview
986
+ </DropdownMenuItem>
987
+ <DropdownMenuItem onClick={() => {
988
+ window.open(`/api/assets/${String(asset.id)}/download`, '_blank');
989
+ }}>
990
+ <Download className="w-4 h-4 mr-2" /> Download
991
+ </DropdownMenuItem>
992
+ <DropdownMenuItem
993
+ className="text-red-600"
994
+ onClick={async () => {
995
+ if (confirm(`Are you sure you want to delete "${asset.name}"?`)) {
996
+ await handleDeleteAsset(String(asset.id));
997
+ }
998
+ }}
999
+ >
1000
  <Trash2 className="w-4 h-4 mr-2" /> Delete
1001
  </DropdownMenuItem>
1002
  </DropdownMenuContent>
 
1030
  className="h-8 w-8 text-red-600 hover:text-red-700 hover:bg-red-50"
1031
  onClick={async () => {
1032
  if (confirm(`Are you sure you want to delete "${previewAsset.name}"?`)) {
1033
+ await handleDeleteAsset(String(previewAsset.id));
1034
  }
1035
  }}
1036
  disabled={isDeleting}
 
1045
  <div className="space-y-4">
1046
  {previewAsset.type === 'image' ? (
1047
  <img
1048
+ src={`/api/assets/${String(previewAsset.id)}/download`}
1049
  alt={previewAsset.name}
1050
  className="max-w-full h-auto rounded-lg mx-auto"
1051
  />
1052
  ) : previewAsset.type === 'video' ? (
1053
  <video
1054
+ src={`/api/assets/${String(previewAsset.id)}/download`}
1055
  controls
1056
  className="max-w-full rounded-lg mx-auto"
1057
  >
 
1073
  This might be because poppler-utils is not installed. PDFs can still be downloaded.
1074
  </p>
1075
  <Button
1076
+ onClick={() => window.open(`/api/assets/${String(previewAsset.id)}/download`, '_blank')}
1077
  variant="outline"
1078
  className="border-red-200 text-red-600 hover:bg-red-100"
1079
  >
 
1107
  <FileText className="w-16 h-16 text-slate-400 mb-4" />
1108
  <p className="text-slate-600 mb-4">Failed to load PDF preview</p>
1109
  <Button
1110
+ onClick={() => window.open(`/api/assets/${String(previewAsset.id)}/download`, '_blank')}
1111
  variant="outline"
1112
  >
1113
  <Download className="w-4 h-4 mr-2" />
 
1121
  <FileText className="w-16 h-16 text-slate-400 mb-4" />
1122
  <p className="text-slate-600 mb-4">Preview not available for this file type</p>
1123
  <Button
1124
+ onClick={() => window.open(`/api/assets/${String(previewAsset.id)}/download`, '_blank')}
1125
  variant="outline"
1126
  >
1127
  <Download className="w-4 h-4 mr-2" />
 
1137
  </div>
1138
  <div className="flex gap-2">
1139
  <Button
1140
+ onClick={() => window.open(`/api/assets/${String(previewAsset.id)}/download`, '_blank')}
1141
  variant="outline"
1142
  >
1143
  <Download className="w-4 h-4 mr-2" />
 
1148
  className="text-red-600 border-red-200 hover:bg-red-50"
1149
  onClick={async () => {
1150
  if (confirm(`Are you sure you want to delete "${previewAsset.name}"?`)) {
1151
+ await handleDeleteAsset(String(previewAsset.id));
1152
  }
1153
  }}
1154
  disabled={isDeleting}