Merge branch 'main' of github.com:lite-note/lite-note into main
This commit is contained in:
@@ -1,32 +1,32 @@
|
||||
import { useUserRepoStore } from '@/modules/repo/store/userRepo.store'
|
||||
import { computed } from 'vue'
|
||||
|
||||
export const useFolderNotes = (folders: string[]) => {
|
||||
const store = useUserRepoStore()
|
||||
|
||||
const fleetingNotes = computed(() =>
|
||||
store.files.filter(
|
||||
(file) =>
|
||||
folders.some((folder) => file.path?.startsWith(folder)) &&
|
||||
file.path?.endsWith('.md')
|
||||
)
|
||||
)
|
||||
|
||||
const content = computed(() =>
|
||||
fleetingNotes.value?.length > 0
|
||||
? fleetingNotes.value
|
||||
.map((note) => {
|
||||
const firstFolder = note.path?.split('/').shift()
|
||||
|
||||
return `- [${note.path?.replace(`${firstFolder}/`, '')}](${
|
||||
note.path
|
||||
})`
|
||||
})
|
||||
.join('\n')
|
||||
: ''
|
||||
)
|
||||
|
||||
return {
|
||||
content
|
||||
}
|
||||
}
|
||||
import { useUserRepoStore } from '@/modules/repo/store/userRepo.store'
|
||||
import { computed } from 'vue'
|
||||
|
||||
export const useFolderNotes = (folders: string[]) => {
|
||||
const store = useUserRepoStore()
|
||||
|
||||
const fleetingNotes = computed(() =>
|
||||
store.files.filter(
|
||||
(file) =>
|
||||
folders.some((folder) => file.path?.startsWith(folder)) &&
|
||||
file.path?.endsWith('.md')
|
||||
)
|
||||
)
|
||||
|
||||
const content = computed(() =>
|
||||
fleetingNotes.value?.length > 0
|
||||
? fleetingNotes.value
|
||||
.map((note) => {
|
||||
const firstFolder = note.path?.split('/').shift()
|
||||
|
||||
return `- [${note.path?.replace(`${firstFolder}/`, '')}](${
|
||||
note.path
|
||||
})`
|
||||
})
|
||||
.join('\n')
|
||||
: ''
|
||||
)
|
||||
|
||||
return {
|
||||
content
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,31 +1,31 @@
|
||||
import { data } from '@/data/data'
|
||||
import { DataType } from '@/data/DataType.enum'
|
||||
import { Note } from '@/modules/note/models/Note'
|
||||
import { useAsyncState } from '@vueuse/core'
|
||||
import { computed } from 'vue'
|
||||
|
||||
export const useNoteCache = (sha: string) => {
|
||||
const noteId = computed(() => data.generateId(DataType.Note, sha))
|
||||
const getCachedNote = async () => data.get<DataType.Note, Note>(noteId.value)
|
||||
|
||||
const cachedNote = useAsyncState(getCachedNote, null)
|
||||
|
||||
const saveCacheNote = async (content: string) => {
|
||||
const newNote: Note = {
|
||||
_id: noteId.value,
|
||||
$type: DataType.Note,
|
||||
content
|
||||
}
|
||||
|
||||
await data.update(newNote)
|
||||
|
||||
await cachedNote.execute()
|
||||
}
|
||||
|
||||
return {
|
||||
cachedNote: cachedNote.state,
|
||||
isReady: cachedNote.isReady,
|
||||
getCachedNote,
|
||||
saveCacheNote
|
||||
}
|
||||
}
|
||||
import { data } from '@/data/data'
|
||||
import { DataType } from '@/data/DataType.enum'
|
||||
import { Note } from '@/modules/note/models/Note'
|
||||
import { useAsyncState } from '@vueuse/core'
|
||||
import { computed } from 'vue'
|
||||
|
||||
export const useNoteCache = (sha: string) => {
|
||||
const noteId = computed(() => data.generateId(DataType.Note, sha))
|
||||
const getCachedNote = async () => data.get<DataType.Note, Note>(noteId.value)
|
||||
|
||||
const cachedNote = useAsyncState(getCachedNote, null)
|
||||
|
||||
const saveCacheNote = async (content: string) => {
|
||||
const newNote: Note = {
|
||||
_id: noteId.value,
|
||||
$type: DataType.Note,
|
||||
content
|
||||
}
|
||||
|
||||
await data.update(newNote)
|
||||
|
||||
await cachedNote.execute()
|
||||
}
|
||||
|
||||
return {
|
||||
cachedNote: cachedNote.state,
|
||||
isReady: cachedNote.isReady,
|
||||
getCachedNote,
|
||||
saveCacheNote
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { DataType } from '@/data/DataType.enum'
|
||||
import { Model } from '@/data/models/Model'
|
||||
|
||||
export interface Note extends Model<DataType.Note> {
|
||||
content: string
|
||||
}
|
||||
import { DataType } from '@/data/DataType.enum'
|
||||
import { Model } from '@/data/models/Model'
|
||||
|
||||
export interface Note extends Model<DataType.Note> {
|
||||
content: string
|
||||
}
|
||||
|
||||
@@ -1,32 +1,32 @@
|
||||
const sanitizePath = (path: string) => {
|
||||
if (path.startsWith('./')) {
|
||||
return decodeURIComponent(path.replace('./', ''))
|
||||
}
|
||||
return decodeURIComponent(path)
|
||||
}
|
||||
|
||||
const removeNoteFilename = (pathNote: string) => {
|
||||
const path = pathNote.split('/')
|
||||
path.pop()
|
||||
|
||||
return sanitizePath(path.join('/'))
|
||||
}
|
||||
|
||||
export const resolvePath = (
|
||||
currentAbsolutePathNote: string,
|
||||
pathToResolve: string
|
||||
) => {
|
||||
let currentAbsolutePath = removeNoteFilename(currentAbsolutePathNote)
|
||||
pathToResolve = sanitizePath(pathToResolve)
|
||||
|
||||
while (pathToResolve.startsWith('../')) {
|
||||
const adjustedAbsolutePath = currentAbsolutePath.split('/')
|
||||
adjustedAbsolutePath.pop()
|
||||
currentAbsolutePath = adjustedAbsolutePath.join('/')
|
||||
pathToResolve = pathToResolve.replace('../', '')
|
||||
}
|
||||
|
||||
return currentAbsolutePath
|
||||
? `${currentAbsolutePath}/${pathToResolve}`
|
||||
: pathToResolve
|
||||
}
|
||||
const sanitizePath = (path: string) => {
|
||||
if (path.startsWith('./')) {
|
||||
return decodeURIComponent(path.replace('./', ''))
|
||||
}
|
||||
return decodeURIComponent(path)
|
||||
}
|
||||
|
||||
const removeNoteFilename = (pathNote: string) => {
|
||||
const path = pathNote.split('/')
|
||||
path.pop()
|
||||
|
||||
return sanitizePath(path.join('/'))
|
||||
}
|
||||
|
||||
export const resolvePath = (
|
||||
currentAbsolutePathNote: string,
|
||||
pathToResolve: string
|
||||
) => {
|
||||
let currentAbsolutePath = removeNoteFilename(currentAbsolutePathNote)
|
||||
pathToResolve = sanitizePath(pathToResolve)
|
||||
|
||||
while (pathToResolve.startsWith('../')) {
|
||||
const adjustedAbsolutePath = currentAbsolutePath.split('/')
|
||||
adjustedAbsolutePath.pop()
|
||||
currentAbsolutePath = adjustedAbsolutePath.join('/')
|
||||
pathToResolve = pathToResolve.replace('../', '')
|
||||
}
|
||||
|
||||
return currentAbsolutePath
|
||||
? `${currentAbsolutePath}/${pathToResolve}`
|
||||
: pathToResolve
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@ import {
|
||||
getMainReadme,
|
||||
getUserSettingsContent
|
||||
} from '@/modules/repo/services/repo'
|
||||
import { refreshToken } from '@/modules/user/service/signIn'
|
||||
import { defineStore } from 'pinia'
|
||||
|
||||
interface State {
|
||||
@@ -29,7 +28,6 @@ export const useUserRepoStore = defineStore({
|
||||
async setUserRepo(newUser: string, newRepo: string) {
|
||||
this.user = newUser
|
||||
this.repo = newRepo
|
||||
await refreshToken()
|
||||
const [readme, files] = await Promise.all([
|
||||
getMainReadme(newUser, newRepo),
|
||||
getFiles(newUser, newRepo)
|
||||
|
||||
@@ -58,8 +58,6 @@ export const refreshToken = async () => {
|
||||
| GithubToken
|
||||
| GithubTokenError
|
||||
|
||||
console.log(githubToken)
|
||||
|
||||
if ('error' in githubToken) {
|
||||
return null
|
||||
}
|
||||
@@ -105,8 +103,6 @@ export const saveAccessToken = async (githubToken: GithubToken) => {
|
||||
username: ''
|
||||
}
|
||||
|
||||
console.log(accessToken)
|
||||
|
||||
const octokit = new Octokit({
|
||||
auth: accessToken?.token
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user