(user settings) init user settings with .litenote.json

This commit is contained in:
2021-03-24 22:33:50 +01:00
parent 55faf04d4f
commit 556ddb7f1e
9 changed files with 96 additions and 31 deletions

View File

@@ -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
}
}