diff --git a/src/main/kotlin/net/taehui/twilight/Twilight.kt b/src/main/kotlin/net/taehui/twilight/Twilight.kt index 1365d33..59d2bb0 100644 --- a/src/main/kotlin/net/taehui/twilight/Twilight.kt +++ b/src/main/kotlin/net/taehui/twilight/Twilight.kt @@ -47,7 +47,7 @@ AbilityClassSystem.loadAbilityClasses() AbilitySystem.loadAbility() BannedIP.loadBannedIP() - BannedNoteFile.loadBannedNoteFile() + BannedNote.loadBannedNote() EdgeSystem.loadEdge() AvatarIPSystem.loadAvatarIP() LevelSystem.loadLevel() @@ -85,7 +85,7 @@ AutoSystem.dispose() AvatarIPSystem.saveAvatarIP() BannedIP.saveBannedIP() - BannedNoteFile.saveBannedNoteFile() + BannedNote.saveBannedNote() Configure.saveConfigure() } } diff --git a/src/main/kotlin/net/taehui/twilight/qwilight/QwilightAvatar.kt b/src/main/kotlin/net/taehui/twilight/qwilight/QwilightAvatar.kt index 018e326..47edb6b 100644 --- a/src/main/kotlin/net/taehui/twilight/qwilight/QwilightAvatar.kt +++ b/src/main/kotlin/net/taehui/twilight/qwilight/QwilightAvatar.kt @@ -800,7 +800,7 @@ val noteFileData = eventData[0].toByteArray() val targetComputing = BaseCompiler.handleCompile(noteFileData, dataID).single() val noteID512 = Utility.getID512(noteFileData) - if (!targetComputing.isBanned && !BannedNoteFile.isBanned(targetComputing.noteID)) { + if (!targetComputing.isBanned && !BannedNote.isBanned(targetComputing.noteID)) { logFuture { Files.write(TwilightComponent.NOTE_ENTRY_PATH.resolve(noteID512), noteFileData) DB.setNote( @@ -948,7 +948,7 @@ val text = jm.readValue(eventText, JSON.QwilightValveComment::class.java) val targetComputing = BaseCompiler.handleCompile(eventData[0].toByteArray(), text.dataID).single() - if (!targetComputing.isBanned && !BannedNoteFile.isBanned(targetComputing.noteID)) { + if (!targetComputing.isBanned && !BannedNote.isBanned(targetComputing.noteID)) { logFuture { if (SiteHandler.hasAvatar(this, SiteHandler.commentSiteID)) { SiteHandler.putSiteYell( diff --git a/src/main/kotlin/net/taehui/twilight/system/BannedNote.kt b/src/main/kotlin/net/taehui/twilight/system/BannedNote.kt new file mode 100644 index 0000000..274b99e --- /dev/null +++ b/src/main/kotlin/net/taehui/twilight/system/BannedNote.kt @@ -0,0 +1,44 @@ +package net.taehui.twilight.system + +import com.fasterxml.jackson.core.type.TypeReference +import com.fasterxml.jackson.databind.ObjectMapper +import net.taehui.twilight.Logger +import java.io.IOException +import java.nio.file.Paths +import java.util.concurrent.ConcurrentHashMap + +object BannedNote : Logger { + private var bannedNoteStore = mutableMapOf() + + fun loadBannedNote() { + try { + bannedNoteStore.putAll( + ObjectMapper().readValue( + Paths.get("Banned Note.json").toFile(), + object : TypeReference>() {}) + ) + logInfo("Loaded Banned Note") + saveBannedNote() + } catch (e: IOException) { + logFault(e) + } + } + + fun saveBannedNote() { + ObjectMapper().writerWithDefaultPrettyPrinter() + .writeValue(Paths.get("Banned Note.json").toFile(), bannedNoteStore) + logInfo("Saved Banned Note") + } + + fun putBannedNoteFile(noteID: String, comment: String) { + bannedNoteStore[noteID] = comment + } + + fun wipeBannedNoteFile(noteID: String) { + bannedNoteStore.remove(noteID) + } + + fun isBanned(noteID: String): Boolean { + return bannedNoteStore.contains(noteID) + } +} \ No newline at end of file diff --git a/src/main/kotlin/net/taehui/twilight/system/BannedNoteFile.kt b/src/main/kotlin/net/taehui/twilight/system/BannedNoteFile.kt deleted file mode 100644 index d636e0b..0000000 --- a/src/main/kotlin/net/taehui/twilight/system/BannedNoteFile.kt +++ /dev/null @@ -1,44 +0,0 @@ -package net.taehui.twilight.system - -import com.fasterxml.jackson.core.type.TypeReference -import com.fasterxml.jackson.databind.ObjectMapper -import net.taehui.twilight.Logger -import java.io.IOException -import java.nio.file.Paths -import java.util.concurrent.ConcurrentHashMap - -object BannedNoteFile : Logger { - private var bannedNoteFileStore = mutableMapOf() - - fun loadBannedNoteFile() { - try { - bannedNoteFileStore.putAll( - ObjectMapper().readValue( - Paths.get("Banned Note File.json").toFile(), - object : TypeReference>() {}) - ) - logInfo("Loaded Banned Note File") - saveBannedNoteFile() - } catch (e: IOException) { - logFault(e) - } - } - - fun saveBannedNoteFile() { - ObjectMapper().writerWithDefaultPrettyPrinter() - .writeValue(Paths.get("Banned Note File.json").toFile(), bannedNoteFileStore) - logInfo("Saved Banned Note File") - } - - fun putBannedNoteFile(noteID: String, comment: String) { - bannedNoteFileStore[noteID] = comment - } - - fun wipeBannedNoteFile(noteID: String) { - bannedNoteFileStore.remove(noteID) - } - - fun isBanned(noteID: String): Boolean { - return bannedNoteFileStore.contains(noteID) - } -} \ No newline at end of file diff --git a/src/main/kotlin/net/taehui/twilight/system/IO.kt b/src/main/kotlin/net/taehui/twilight/system/IO.kt index cbad708..78aecb0 100644 --- a/src/main/kotlin/net/taehui/twilight/system/IO.kt +++ b/src/main/kotlin/net/taehui/twilight/system/IO.kt @@ -339,7 +339,7 @@ "ban" -> { if (w.size > 3) { - BannedNoteFile.putBannedNoteFile(w[2], w[3]) + BannedNote.putBannedNoteFile(w[2], w[3]) } else { logInfo("note ban ") } @@ -348,7 +348,7 @@ "allow" -> { if (w.size > 2) { - BannedNoteFile.wipeBannedNoteFile(w[2]) + BannedNote.wipeBannedNoteFile(w[2]) } else { logInfo("note allow ") } diff --git a/src/main/kotlin/net/taehui/twilight/www/WwwAvatar.kt b/src/main/kotlin/net/taehui/twilight/www/WwwAvatar.kt index 76683a1..8f328ce 100644 --- a/src/main/kotlin/net/taehui/twilight/www/WwwAvatar.kt +++ b/src/main/kotlin/net/taehui/twilight/www/WwwAvatar.kt @@ -141,7 +141,7 @@ "/qwilight/www/comment" -> { val noteID = params.getOrDefault("noteID", "") - if (BannedNoteFile.isBanned(noteID)) { + if (BannedNote.isBanned(noteID)) { send(ctx, object { val favor = null val totalFavor = 0 @@ -591,23 +591,29 @@ "/qwilight/www/note" -> { val noteFileData = ByteBufUtil.getBytes(msg.content()) - val targetComputing = BaseCompiler.handleCompile(noteFileData, 0).single() - if (targetComputing.isBanned || BannedNoteFile.isBanned(targetComputing.noteID)) { + var isBanned = false + BaseCompiler.handleCompile(noteFileData, -1).forEach { + if (it.isBanned || BannedNote.isBanned(it.noteID)) { + isBanned = true + } else { + logFuture { + Files.write( + TwilightComponent.NOTE_ENTRY_PATH.resolve(Utility.getID512(noteFileData)), + noteFileData + ) + DB.setNote( + it.noteID, + Utility.getID128(noteFileData), + Utility.getID256(noteFileData), + it + ) + } + } + } + if (isBanned) { send403(ctx) } else { - logFuture { - Files.write( - TwilightComponent.NOTE_ENTRY_PATH.resolve(Utility.getID512(noteFileData)), - noteFileData - ) - DB.setNote( - targetComputing.noteID, - Utility.getID128(noteFileData), - Utility.getID256(noteFileData), - targetComputing - ) - send204(ctx) - } + send204(ctx) } }