techedstudios commited on
Commit
c65ab7d
·
1 Parent(s): 5f623fc

Fix HF Datasets backup for duplicated spaces and sanitize dataset names

Browse files
Files changed (1) hide show
  1. backend/sync-manager.js +7 -3
backend/sync-manager.js CHANGED
@@ -6,7 +6,7 @@ import path from "path";
6
  import AdmZip from "adm-zip";
7
 
8
  // ─── Config ───────────────────────────────────────────────────────────────────
9
- const HF_OWNER = "techedstudios";
10
  const MAX_BACKUPS = 5; // Keep last 5 backups (unlimited space on HF!)
11
 
12
  function getHFToken() {
@@ -14,8 +14,12 @@ function getHFToken() {
14
  }
15
 
16
  function getRepoId(serverId) {
17
- const sanitizedId = serverId.replace(/\./g, '-');
18
- return `${HF_OWNER}/mc-server-data-${sanitizedId}`;
 
 
 
 
19
  }
20
 
21
  // ─── Ensure HF Dataset exists ─────────────────────────────────────────────────
 
6
  import AdmZip from "adm-zip";
7
 
8
  // ─── Config ───────────────────────────────────────────────────────────────────
9
+ const HF_OWNER = process.env.SPACE_AUTHOR_NAME || "techedstudios";
10
  const MAX_BACKUPS = 5; // Keep last 5 backups (unlimited space on HF!)
11
 
12
  function getHFToken() {
 
14
  }
15
 
16
  function getRepoId(serverId) {
17
+ const sanitizedId = serverId
18
+ .replace(/\./g, '-')
19
+ .replace(/[^a-zA-Z0-9-_\.]/g, '-')
20
+ .replace(/-+/g, '-')
21
+ .replace(/^-+|-+$/g, '');
22
+ return `${HF_OWNER}/mc-server-data-${sanitizedId}`.toLowerCase();
23
  }
24
 
25
  // ─── Ensure HF Dataset exists ─────────────────────────────────────────────────