can edit raw content
This commit is contained in:
@@ -6,7 +6,9 @@ import { getFileContent } from '@/modules/repo/services/repo'
|
||||
import { useUserRepoStore } from '@/modules/repo/store/userRepo.store'
|
||||
|
||||
export const useFile = (sha: Ref<string> | string, retrieveContent = true) => {
|
||||
const { render } = useMarkdown(toValue(sha))
|
||||
const { render, getRawContent: getRawContentFromFile } = useMarkdown(
|
||||
toValue(sha)
|
||||
)
|
||||
const store = useUserRepoStore()
|
||||
const { getCachedNote, saveCacheNote } = prepareNoteCache(toValue(sha))
|
||||
const fromCache = ref(false)
|
||||
@@ -14,26 +16,6 @@ export const useFile = (sha: Ref<string> | string, retrieveContent = true) => {
|
||||
const content = ref('')
|
||||
const rawContent = ref('')
|
||||
|
||||
const getRawContent = async () => {
|
||||
const fileContent = await getCachedFileContent()
|
||||
if (!fileContent) {
|
||||
return
|
||||
}
|
||||
content.value = render(fileContent)
|
||||
rawContent.value = fileContent
|
||||
return rawContent.value
|
||||
}
|
||||
|
||||
const getContent = async () => {
|
||||
const fileContent = await getCachedFileContent()
|
||||
if (!fileContent) {
|
||||
return
|
||||
}
|
||||
content.value = render(fileContent)
|
||||
rawContent.value = fileContent
|
||||
return content.value
|
||||
}
|
||||
|
||||
const getCachedFileContent = async (): Promise<string | null> => {
|
||||
const cachedNote = await getCachedNote()
|
||||
|
||||
@@ -57,12 +39,32 @@ export const useFile = (sha: Ref<string> | string, retrieveContent = true) => {
|
||||
return contentFile
|
||||
}
|
||||
|
||||
const getRawContent = async () => {
|
||||
const fileContent = await getCachedFileContent()
|
||||
if (!fileContent) {
|
||||
return
|
||||
}
|
||||
rawContent.value = getRawContentFromFile(fileContent)
|
||||
return rawContent.value
|
||||
}
|
||||
|
||||
const getContent = async () => {
|
||||
const fileContent = await getCachedFileContent()
|
||||
if (!fileContent) {
|
||||
return
|
||||
}
|
||||
content.value = render(fileContent)
|
||||
return content.value
|
||||
}
|
||||
|
||||
if (retrieveContent) {
|
||||
getContent()
|
||||
getRawContent()
|
||||
}
|
||||
|
||||
return {
|
||||
content,
|
||||
rawContent,
|
||||
getRawContent,
|
||||
getContent,
|
||||
getCachedFileContent,
|
||||
|
||||
@@ -40,6 +40,8 @@ const md = new MarkdownIt({
|
||||
})
|
||||
|
||||
export const useMarkdown = (defaultPrefix?: Ref<string> | string) => {
|
||||
const getRawContent = (content: string) => decodeBase64ToUTF8(content)
|
||||
|
||||
return {
|
||||
toHTML: (content: string) => (content ? md.render(content) : ''),
|
||||
render: (content: string, prefix?: string) =>
|
||||
@@ -47,6 +49,7 @@ export const useMarkdown = (defaultPrefix?: Ref<string> | string) => {
|
||||
? md.render(decodeBase64ToUTF8(content), {
|
||||
docId: defaultPrefix ? toValue(defaultPrefix) : prefix ?? ''
|
||||
})
|
||||
: ''
|
||||
: '',
|
||||
getRawContent
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user