-
Notifications
You must be signed in to change notification settings - Fork 552
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create re-usable file service for reading git blobs
- decouples reading from workspace from reading from commit
- Loading branch information
Showing
9 changed files
with
115 additions
and
75 deletions.
There are no files selected for viewing
This file contains 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 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,6 @@ | ||
export type FileInfo = { | ||
content: string; | ||
name?: string; | ||
mimeType?: string; | ||
size?: number; | ||
}; |
This file contains 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,33 @@ | ||
import type { Tauri } from '$lib/backend/tauri'; | ||
import type { FileInfo } from './file'; | ||
|
||
export class FileService { | ||
constructor(private tauri: Tauri) {} | ||
|
||
async readFromWorkspace(filePath: string, projectId: string) { | ||
const data: FileInfo = await this.tauri.invoke('get_workspace_file', { | ||
relativePath: filePath, | ||
projectId: projectId | ||
}); | ||
return { | ||
data, | ||
isLarge: isLarge(data.size) | ||
}; | ||
} | ||
|
||
async readFromCommit(filePath: string, projectId: string, commitId: string | undefined) { | ||
const data: FileInfo = await this.tauri.invoke('get_commit_file', { | ||
relativePath: filePath, | ||
projectId: projectId, | ||
commitId | ||
}); | ||
return { | ||
data, | ||
isLarge: isLarge(data.size) | ||
}; | ||
} | ||
} | ||
|
||
function isLarge(size: number | undefined) { | ||
return size && size > 5 * 1024 * 1024 ? true : false; | ||
} |
This file contains 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 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 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 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 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 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