mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2026-01-09 06:49:02 +08:00
refactor: Store default notes path as relative for portability
- Changed getNotesDir() to return './Data/Notes' instead of absolute path - Added getNotesDirAbsolute() for cases requiring absolute paths - Updated FileStorage to use getNotesDirAbsolute() - Added tests for both functions This allows the default notes path to be portable across devices while externally selected paths remain absolute. Co-authored-by: DeJeune <67425183+DeJeune@users.noreply.github.com>
This commit is contained in:
parent
cbd4f418f6
commit
6493f1853d
@ -5,7 +5,7 @@ import {
|
|||||||
getFilesDir,
|
getFilesDir,
|
||||||
getFileType,
|
getFileType,
|
||||||
getName,
|
getName,
|
||||||
getNotesDir,
|
getNotesDirAbsolute,
|
||||||
getTempDir,
|
getTempDir,
|
||||||
readTextFileWithAutoEncoding,
|
readTextFileWithAutoEncoding,
|
||||||
scanDir
|
scanDir
|
||||||
@ -57,7 +57,7 @@ const DEFAULT_WATCHER_CONFIG: Required<FileWatcherConfig> = {
|
|||||||
|
|
||||||
class FileStorage {
|
class FileStorage {
|
||||||
private storageDir = getFilesDir()
|
private storageDir = getFilesDir()
|
||||||
private notesDir = getNotesDir()
|
private notesDir = getNotesDirAbsolute()
|
||||||
private tempDir = getTempDir()
|
private tempDir = getTempDir()
|
||||||
private watcher?: FSWatcher
|
private watcher?: FSWatcher
|
||||||
private watcherSender?: Electron.WebContents
|
private watcherSender?: Electron.WebContents
|
||||||
@ -774,7 +774,7 @@ class FileStorage {
|
|||||||
// Get app paths to prevent selection of restricted directories
|
// Get app paths to prevent selection of restricted directories
|
||||||
const appDataPath = path.resolve(process.env.APPDATA || path.join(require('os').homedir(), '.config'))
|
const appDataPath = path.resolve(process.env.APPDATA || path.join(require('os').homedir(), '.config'))
|
||||||
const filesDir = path.resolve(getFilesDir())
|
const filesDir = path.resolve(getFilesDir())
|
||||||
const currentNotesDir = path.resolve(getNotesDir())
|
const currentNotesDir = getNotesDirAbsolute()
|
||||||
|
|
||||||
// Prevent selecting app data directories
|
// Prevent selecting app data directories
|
||||||
if (
|
if (
|
||||||
|
|||||||
@ -16,6 +16,8 @@ import {
|
|||||||
getConfigDir,
|
getConfigDir,
|
||||||
getFilesDir,
|
getFilesDir,
|
||||||
getFileType,
|
getFileType,
|
||||||
|
getNotesDir,
|
||||||
|
getNotesDirAbsolute,
|
||||||
getTempDir,
|
getTempDir,
|
||||||
isPathInside,
|
isPathInside,
|
||||||
untildify
|
untildify
|
||||||
@ -245,6 +247,20 @@ describe('file', () => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe('getNotesDir', () => {
|
||||||
|
it('should return relative path for portability', () => {
|
||||||
|
const notesDir = getNotesDir()
|
||||||
|
expect(notesDir).toBe('./Data/Notes')
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('getNotesDirAbsolute', () => {
|
||||||
|
it('should return absolute notes directory path', () => {
|
||||||
|
const notesDirAbsolute = getNotesDirAbsolute()
|
||||||
|
expect(notesDirAbsolute).toBe('/mock/userData/Data/Notes')
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
describe('getAppConfigDir', () => {
|
describe('getAppConfigDir', () => {
|
||||||
it('should return correct app config directory path', () => {
|
it('should return correct app config directory path', () => {
|
||||||
const appConfigDir = getAppConfigDir('test-app')
|
const appConfigDir = getAppConfigDir('test-app')
|
||||||
|
|||||||
@ -183,7 +183,12 @@ export function getNotesDir() {
|
|||||||
fs.mkdirSync(notesDir, { recursive: true })
|
fs.mkdirSync(notesDir, { recursive: true })
|
||||||
logger.info(`Notes directory created at: ${notesDir}`)
|
logger.info(`Notes directory created at: ${notesDir}`)
|
||||||
}
|
}
|
||||||
return notesDir
|
// Return relative path for better portability across devices
|
||||||
|
return './Data/Notes'
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getNotesDirAbsolute() {
|
||||||
|
return path.join(app.getPath('userData'), 'Data', 'Notes')
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getConfigDir() {
|
export function getConfigDir() {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user