Newer
Older
Twilight / src / main / kotlin / net / taehui / twilight / system / NoteFilesSystem.kt
@Taehui Taehui on 8 Jul 888 bytes v1.0-SNAPSHOT
package net.taehui.twilight.system

import net.taehui.twilight.Logger
import net.taehui.twilight.TwilightComponent
import net.taehui.twilight.Utility
import java.nio.file.Path
import java.util.concurrent.ConcurrentHashMap

object NoteFilesSystem : Logger {
    private var noteFiles = ConcurrentHashMap<String, Path>()

    fun loadNoteFiles() {
        DB.getNotes().thenAccept { notes ->
            noteFiles = ConcurrentHashMap(notes.associateWith {
                TwilightComponent.NOTE_ENTRY_PATH.resolve(Utility.getNoteID512(it))
            })
            logInfo("Loaded Note Files")
        }
    }

    val noteFile: Map.Entry<String, Path>?
        get() = noteFiles.entries.randomOrNull()

    fun getNoteFile(noteID: String): Path? {
        return noteFiles[noteID]
    }

    fun hasNoteFile(noteID: String): Boolean {
        return noteFiles.containsKey(noteID)
    }
}