mohsin-devs commited on
Commit
a158e71
·
1 Parent(s): 9ca21f5

Fix file preview URLs by routing through backend download endpoint

Browse files
Files changed (2) hide show
  1. js/main.js +2 -2
  2. js/utils/formatters.js +2 -2
js/main.js CHANGED
@@ -238,7 +238,7 @@ class App {
238
  onDownload: (url, name) => this.downloadFile(url, name),
239
  onStar: (path) => this.state.toggleStar(path),
240
  onDelete: (path, name) => this.openDeleteModal(path, name),
241
- getUrl: (path) => getFileUrl(this.hf.username, this.hf.dataset, path)
242
  });
243
 
244
  this.updateActiveNavItem();
@@ -359,7 +359,7 @@ class App {
359
 
360
  openPreview(file) {
361
  this.state.addToRecent(file);
362
- const url = getFileUrl(this.hf.username, this.hf.dataset, file.path);
363
  const modal = document.getElementById('previewModal');
364
  const body = document.getElementById('previewBody');
365
  const title = document.getElementById('previewFileName');
 
238
  onDownload: (url, name) => this.downloadFile(url, name),
239
  onStar: (path) => this.state.toggleStar(path),
240
  onDelete: (path, name) => this.openDeleteModal(path, name),
241
+ getUrl: (path) => getFileUrl(this.hf.apiBase, path)
242
  });
243
 
244
  this.updateActiveNavItem();
 
359
 
360
  openPreview(file) {
361
  this.state.addToRecent(file);
362
+ const url = getFileUrl(this.hf.apiBase, file.path);
363
  const modal = document.getElementById('previewModal');
364
  const body = document.getElementById('previewBody');
365
  const title = document.getElementById('previewFileName');
js/utils/formatters.js CHANGED
@@ -57,7 +57,7 @@ export function formatDate(timestamp) {
57
  return `${Math.floor(diffDays / 365)} years ago`;
58
  }
59
 
60
- export function getFileUrl(username, dataset, filePath) {
61
  const encoded = filePath.split('/').map(encodeURIComponent).join('/');
62
- return `https://huggingface.co/datasets/${encodeURIComponent(username)}/${encodeURIComponent(dataset)}/resolve/main/${encoded}`;
63
  }
 
57
  return `${Math.floor(diffDays / 365)} years ago`;
58
  }
59
 
60
+ export function getFileUrl(apiBase, filePath) {
61
  const encoded = filePath.split('/').map(encodeURIComponent).join('/');
62
+ return `${apiBase}/download/${encoded}`;
63
  }