🐛 (images) get file content for images
This commit is contained in:
@@ -84,7 +84,7 @@ export default defineComponent({
|
|||||||
const { stackedNotes, resetStackedNotes } = useQueryStackedNotes()
|
const { stackedNotes, resetStackedNotes } = useQueryStackedNotes()
|
||||||
const { scrollToFocusedNote } = useFocus()
|
const { scrollToFocusedNote } = useFocus()
|
||||||
|
|
||||||
const { ...noteProps } = useNote('note-container')
|
const { titles } = useNote('note-container')
|
||||||
|
|
||||||
const renderedContent = computed(() =>
|
const renderedContent = computed(() =>
|
||||||
props.content !== null ? renderString(props.content) : store.readme
|
props.content !== null ? renderString(props.content) : store.readme
|
||||||
@@ -123,7 +123,7 @@ export default defineComponent({
|
|||||||
resetStackedNotes,
|
resetStackedNotes,
|
||||||
userSettings: computed(() => store.userSettings),
|
userSettings: computed(() => store.userSettings),
|
||||||
focus: () => scrollToFocusedNote(undefined, true),
|
focus: () => scrollToFocusedNote(undefined, true),
|
||||||
...noteProps
|
titles
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import { useUserRepoStore } from '@/modules/repo/store/userRepo.store'
|
|||||||
import { getFileContent } from '@/modules/repo/services/repo'
|
import { getFileContent } from '@/modules/repo/services/repo'
|
||||||
|
|
||||||
export const useFile = (sha: string, retrieveContent = true) => {
|
export const useFile = (sha: string, retrieveContent = true) => {
|
||||||
|
const { render } = useMarkdown()
|
||||||
const store = useUserRepoStore()
|
const store = useUserRepoStore()
|
||||||
const { getCachedNote, saveCacheNote } = useNoteCache(sha)
|
const { getCachedNote, saveCacheNote } = useNoteCache(sha)
|
||||||
const fromCache = ref(false)
|
const fromCache = ref(false)
|
||||||
@@ -12,23 +13,29 @@ export const useFile = (sha: string, retrieveContent = true) => {
|
|||||||
const content = ref('')
|
const content = ref('')
|
||||||
|
|
||||||
const getContent = async () => {
|
const getContent = async () => {
|
||||||
const { render } = useMarkdown()
|
const fileContent = await getCachedFileContent()
|
||||||
const contentFile = await getFileContent(store.user, store.repo, sha)
|
if (!fileContent) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
content.value = render(fileContent)
|
||||||
|
}
|
||||||
|
|
||||||
|
const getCachedFileContent = async (): Promise<string | null> => {
|
||||||
const cachedNote = await getCachedNote()
|
const cachedNote = await getCachedNote()
|
||||||
|
|
||||||
fromCache.value = !!cachedNote
|
fromCache.value = !!cachedNote
|
||||||
|
|
||||||
if (cachedNote) {
|
if (cachedNote) {
|
||||||
content.value = render(cachedNote.content)
|
return cachedNote.content
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const contentFile = await getFileContent(store.user, store.repo, sha)
|
||||||
|
|
||||||
if (!contentFile) {
|
if (!contentFile) {
|
||||||
return
|
return null
|
||||||
}
|
}
|
||||||
saveCacheNote(contentFile)
|
saveCacheNote(contentFile)
|
||||||
content.value = render(contentFile)
|
return contentFile
|
||||||
}
|
}
|
||||||
|
|
||||||
if (retrieveContent) {
|
if (retrieveContent) {
|
||||||
@@ -38,6 +45,7 @@ export const useFile = (sha: string, retrieveContent = true) => {
|
|||||||
return {
|
return {
|
||||||
content,
|
content,
|
||||||
getContent,
|
getContent,
|
||||||
|
getCachedFileContent,
|
||||||
fromCache
|
fromCache
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,9 +31,9 @@ export const useImages = (sha: string) => {
|
|||||||
if (!imageFile?.sha) {
|
if (!imageFile?.sha) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
const { getContent } = useFile(imageFile.sha, false)
|
const { getCachedFileContent } = useFile(imageFile.sha, false)
|
||||||
|
|
||||||
const fileContent = await getContent()
|
const fileContent = await getCachedFileContent()
|
||||||
image.setAttribute('src', `${SRC_PREFIX} ${fileContent}`)
|
image.setAttribute('src', `${SRC_PREFIX} ${fileContent}`)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user