Repository navigation
Codex/standardize backup names errors #27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| /** | ||
| * Shared backup filename helpers used by: | ||
| * - the list-page "Export" download (local JSON backup), and | ||
| * - the Google Drive manual backup upload. | ||
| * | ||
| * Why this exists: | ||
| * - Users should see one consistent naming convention everywhere. | ||
| * - The timestamp should be readable and lexicographically sortable. | ||
| * - The `-g<groupCount>` suffix helps identify the approximate backup size without opening it. | ||
| * | ||
| * Canonical format: | ||
| * `nufftabs-backup-<timestamp>-g<groupCount>.json` | ||
| * | ||
| * Example: | ||
| * `nufftabs-backup-2026-02-23T02-20-49-747Z-g22.json` | ||
| */ | ||
|
|
||
| /** File prefix used for all NuffTabs backup downloads/uploads. */ | ||
| export const NUFFTABS_BACKUP_FILE_PREFIX = 'nufftabs-backup'; | ||
|
|
||
| /** | ||
| * Converts an epoch-ms timestamp into the filename-friendly ISO segment used by backup files. | ||
| * | ||
| * Notes: | ||
| * - Uses UTC via `toISOString()` so backups are comparable across machines/timezones. | ||
| * - Replaces `:` and `.` with `-` so the filename is Windows-friendly and matches prior behavior. | ||
| */ | ||
| export function formatBackupTimestampSegment(timestampMs: number): string { | ||
| const safeTimestamp = Number.isFinite(timestampMs) ? timestampMs : Date.now(); | ||
| return new Date(safeTimestamp).toISOString().replace(/[:.]/g, '-'); | ||
| } | ||
|
|
||
| /** | ||
| * Creates a standardized backup filename embedding the timestamp and tab-group count. | ||
| * The returned string is safe to use as a download name and as a Drive file name. | ||
| */ | ||
| export function createNufftabsBackupFileName(timestampMs: number, tabGroupCount: number): string { | ||
| const timestampSegment = formatBackupTimestampSegment(timestampMs); | ||
| const normalizedGroupCount = Math.max(0, Math.floor(tabGroupCount)); | ||
| return `${NUFFTABS_BACKUP_FILE_PREFIX}-${timestampSegment}-g${normalizedGroupCount}.json`; | ||
| } | ||
|
|
||
| /** | ||
| * Extracts the `-g<groupCount>` suffix from a backup filename. | ||
| * | ||
| * This intentionally does not require the canonical prefix so older/foreign names | ||
| * can still be surfaced in the UI with a best-effort group count. | ||
| */ | ||
| export function extractTabGroupCountFromBackupFileName(fileName: string): number { | ||
| const match = /-g(\d+)\.json$/i.exec(fileName); | ||
| if (!match) return 0; | ||
| const parsed = Number(match[1]); | ||
| return Number.isFinite(parsed) && parsed > 0 ? Math.floor(parsed) : 0; | ||
| } | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| import { describe, expect, it } from 'vitest'; | ||
| import { | ||
| NUFFTABS_BACKUP_FILE_PREFIX, | ||
| createNufftabsBackupFileName, | ||
| extractTabGroupCountFromBackupFileName, | ||
| formatBackupTimestampSegment, | ||
| } from '../../entrypoints/shared/backup_filename'; | ||
|
|
||
| describe('backup filename helpers', () => { | ||
| it('formats timestamps as filename-safe ISO segments', () => { | ||
| expect(formatBackupTimestampSegment(0)).toBe('1970-01-01T00-00-00-000Z'); | ||
| }); | ||
|
|
||
| it('creates canonical backup filenames with group counts', () => { | ||
| const name = createNufftabsBackupFileName(Date.parse('2026-02-23T02:20:49.747Z'), 22); | ||
| expect(name).toBe('nufftabs-backup-2026-02-23T02-20-49-747Z-g22.json'); | ||
| expect(name.startsWith(`${NUFFTABS_BACKUP_FILE_PREFIX}-`)).toBe(true); | ||
| expect(extractTabGroupCountFromBackupFileName(name)).toBe(22); | ||
| }); | ||
|
|
||
| it('returns 0 group count when missing or invalid', () => { | ||
| expect(extractTabGroupCountFromBackupFileName('nufftabs-backup-2026-02-23T02-20-49-747Z.json')).toBe(0); | ||
| expect(extractTabGroupCountFromBackupFileName('nufftabs-backup-2026-02-23T02-20-49-747Z-g0.json')).toBe(0); | ||
| expect(extractTabGroupCountFromBackupFileName('nope.json')).toBe(0); | ||
| }); | ||
| }); | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.