✨ (user settings) init user settings with .litenote.json
This commit is contained in:
@@ -1,42 +1,19 @@
|
||||
import { ref } from 'vue'
|
||||
import { useMarkdown } from '@/hooks/useMarkdown.hook'
|
||||
import { useGitHubLogin } from '@/hooks/useGitHubLogin.hook'
|
||||
import { Octokit } from '@octokit/rest'
|
||||
import { useNoteCache } from '@/modules/note/hooks/useNoteCache'
|
||||
import { useUserRepoStore } from '@/modules/repo/store/userRepo.store'
|
||||
import { getFileContent } from '@/modules/repo/services/repo'
|
||||
|
||||
export const useFile = (sha: string, retrieveContent = true) => {
|
||||
const store = useUserRepoStore()
|
||||
const { getCachedNote, saveCacheNote } = useNoteCache(sha)
|
||||
const { accessToken } = useGitHubLogin()
|
||||
const fromCache = ref(false)
|
||||
|
||||
const octokit = new Octokit({
|
||||
auth: accessToken.value
|
||||
})
|
||||
|
||||
const content = ref('')
|
||||
|
||||
const getFileContent = async () => {
|
||||
if (!store.user || !store.repo) {
|
||||
null
|
||||
}
|
||||
|
||||
const file = await octokit.request(
|
||||
'GET /repos/{owner}/{repo}/git/blobs/{file_sha}',
|
||||
{
|
||||
owner: store.user,
|
||||
repo: store.repo,
|
||||
file_sha: sha
|
||||
}
|
||||
)
|
||||
|
||||
return file?.data.content ?? null
|
||||
}
|
||||
|
||||
const getContent = async () => {
|
||||
const { render } = useMarkdown()
|
||||
const contentFile = await getFileContent()
|
||||
const contentFile = await getFileContent(store.user, store.repo, sha)
|
||||
|
||||
const cachedNote = await getCachedNote()
|
||||
|
||||
@@ -60,7 +37,7 @@ export const useFile = (sha: string, retrieveContent = true) => {
|
||||
|
||||
return {
|
||||
content,
|
||||
getFileContent,
|
||||
getContent,
|
||||
fromCache
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user