Initial commit
This commit is contained in:
36 files changed
+5204
No files matched your search
@@ -0,0 +1,6 @@
|
||||
.idea/
|
||||
.gradle/
|
||||
.kotlin/
|
||||
KSnippets.iml
|
||||
**/build/
|
||||
/snippets-backend/data/
|
||||
@@ -0,0 +1,13 @@
|
||||
plugins {
|
||||
kotlin("multiplatform") version "2.4.10" apply false
|
||||
kotlin("plugin.serialization") version "2.4.10" apply false
|
||||
}
|
||||
|
||||
allprojects {
|
||||
group = "cn.rtast.snippets"
|
||||
version = "1.0"
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
kotlin.code.style=official
|
||||
kotlin.native.ignoreDisabledTargets=true
|
||||
org.gradle.jvmargs=-Xmx2048m -XX:+UseParallelGC -XX:MaxMetaspaceSize=512m
|
||||
Vendored
BIN
Binary file not shown.
+6
@@ -0,0 +1,6 @@
|
||||
#Thu Aug 27 18:04:29 CST 2026
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-9.6.0-bin.zip
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
@@ -0,0 +1,234 @@
|
||||
#!/bin/sh
|
||||
|
||||
#
|
||||
# Copyright © 2015-2021 the original authors.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# https://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
##############################################################################
|
||||
#
|
||||
# Gradle start up script for POSIX generated by Gradle.
|
||||
#
|
||||
# Important for running:
|
||||
#
|
||||
# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
|
||||
# noncompliant, but you have some other compliant shell such as ksh or
|
||||
# bash, then to run this script, type that shell name before the whole
|
||||
# command line, like:
|
||||
#
|
||||
# ksh Gradle
|
||||
#
|
||||
# Busybox and similar reduced shells will NOT work, because this script
|
||||
# requires all of these POSIX shell features:
|
||||
# * functions;
|
||||
# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
|
||||
# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
|
||||
# * compound commands having a testable exit status, especially «case»;
|
||||
# * various built-in commands including «command», «set», and «ulimit».
|
||||
#
|
||||
# Important for patching:
|
||||
#
|
||||
# (2) This script targets any POSIX shell, so it avoids extensions provided
|
||||
# by Bash, Ksh, etc; in particular arrays are avoided.
|
||||
#
|
||||
# The "traditional" practice of packing multiple parameters into a
|
||||
# space-separated string is a well documented source of bugs and security
|
||||
# problems, so this is (mostly) avoided, by progressively accumulating
|
||||
# options in "$@", and eventually passing that to Java.
|
||||
#
|
||||
# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
|
||||
# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
|
||||
# see the in-line comments for details.
|
||||
#
|
||||
# There are tweaks for specific operating systems such as AIX, CygWin,
|
||||
# Darwin, MinGW, and NonStop.
|
||||
#
|
||||
# (3) This script is generated from the Groovy template
|
||||
# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
||||
# within the Gradle project.
|
||||
#
|
||||
# You can find Gradle at https://github.com/gradle/gradle/.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
# Attempt to set APP_HOME
|
||||
|
||||
# Resolve links: $0 may be a link
|
||||
app_path=$0
|
||||
|
||||
# Need this for daisy-chained symlinks.
|
||||
while
|
||||
APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
|
||||
[ -h "$app_path" ]
|
||||
do
|
||||
ls=$( ls -ld "$app_path" )
|
||||
link=${ls#*' -> '}
|
||||
case $link in #(
|
||||
/*) app_path=$link ;; #(
|
||||
*) app_path=$APP_HOME$link ;;
|
||||
esac
|
||||
done
|
||||
|
||||
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
|
||||
|
||||
APP_NAME="Gradle"
|
||||
APP_BASE_NAME=${0##*/}
|
||||
|
||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||
|
||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||
MAX_FD=maximum
|
||||
|
||||
warn () {
|
||||
echo "$*"
|
||||
} >&2
|
||||
|
||||
die () {
|
||||
echo
|
||||
echo "$*"
|
||||
echo
|
||||
exit 1
|
||||
} >&2
|
||||
|
||||
# OS specific support (must be 'true' or 'false').
|
||||
cygwin=false
|
||||
msys=false
|
||||
darwin=false
|
||||
nonstop=false
|
||||
case "$( uname )" in #(
|
||||
CYGWIN* ) cygwin=true ;; #(
|
||||
Darwin* ) darwin=true ;; #(
|
||||
MSYS* | MINGW* ) msys=true ;; #(
|
||||
NONSTOP* ) nonstop=true ;;
|
||||
esac
|
||||
|
||||
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
||||
|
||||
|
||||
# Determine the Java command to use to start the JVM.
|
||||
if [ -n "$JAVA_HOME" ] ; then
|
||||
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
||||
# IBM's JDK on AIX uses strange locations for the executables
|
||||
JAVACMD=$JAVA_HOME/jre/sh/java
|
||||
else
|
||||
JAVACMD=$JAVA_HOME/bin/java
|
||||
fi
|
||||
if [ ! -x "$JAVACMD" ] ; then
|
||||
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
else
|
||||
JAVACMD=java
|
||||
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
|
||||
# Increase the maximum file descriptors if we can.
|
||||
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
|
||||
case $MAX_FD in #(
|
||||
max*)
|
||||
MAX_FD=$( ulimit -H -n ) ||
|
||||
warn "Could not query maximum file descriptor limit"
|
||||
esac
|
||||
case $MAX_FD in #(
|
||||
'' | soft) :;; #(
|
||||
*)
|
||||
ulimit -n "$MAX_FD" ||
|
||||
warn "Could not set maximum file descriptor limit to $MAX_FD"
|
||||
esac
|
||||
fi
|
||||
|
||||
# Collect all arguments for the java command, stacking in reverse order:
|
||||
# * args from the command line
|
||||
# * the main class name
|
||||
# * -classpath
|
||||
# * -D...appname settings
|
||||
# * --module-path (only if needed)
|
||||
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
|
||||
|
||||
# For Cygwin or MSYS, switch paths to Windows format before running java
|
||||
if "$cygwin" || "$msys" ; then
|
||||
APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
|
||||
CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
|
||||
|
||||
JAVACMD=$( cygpath --unix "$JAVACMD" )
|
||||
|
||||
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
||||
for arg do
|
||||
if
|
||||
case $arg in #(
|
||||
-*) false ;; # don't mess with options #(
|
||||
/?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
|
||||
[ -e "$t" ] ;; #(
|
||||
*) false ;;
|
||||
esac
|
||||
then
|
||||
arg=$( cygpath --path --ignore --mixed "$arg" )
|
||||
fi
|
||||
# Roll the args list around exactly as many times as the number of
|
||||
# args, so each arg winds up back in the position where it started, but
|
||||
# possibly modified.
|
||||
#
|
||||
# NB: a `for` loop captures its iteration list before it begins, so
|
||||
# changing the positional parameters here affects neither the number of
|
||||
# iterations, nor the values presented in `arg`.
|
||||
shift # remove old arg
|
||||
set -- "$@" "$arg" # push replacement arg
|
||||
done
|
||||
fi
|
||||
|
||||
# Collect all arguments for the java command;
|
||||
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
|
||||
# shell script including quotes and variable substitutions, so put them in
|
||||
# double quotes to make sure that they get re-expanded; and
|
||||
# * put everything else in single quotes, so that it's not re-expanded.
|
||||
|
||||
set -- \
|
||||
"-Dorg.gradle.appname=$APP_BASE_NAME" \
|
||||
-classpath "$CLASSPATH" \
|
||||
org.gradle.wrapper.GradleWrapperMain \
|
||||
"$@"
|
||||
|
||||
# Use "xargs" to parse quoted args.
|
||||
#
|
||||
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
|
||||
#
|
||||
# In Bash we could simply go:
|
||||
#
|
||||
# readarray ARGS < <( xargs -n1 <<<"$var" ) &&
|
||||
# set -- "${ARGS[@]}" "$@"
|
||||
#
|
||||
# but POSIX shell has neither arrays nor command substitution, so instead we
|
||||
# post-process each arg (as a line of input to sed) to backslash-escape any
|
||||
# character that might be a shell metacharacter, then use eval to reverse
|
||||
# that process (while maintaining the separation between arguments), and wrap
|
||||
# the whole thing up as a single "set" statement.
|
||||
#
|
||||
# This will of course break if any of these variables contains a newline or
|
||||
# an unmatched quote.
|
||||
#
|
||||
|
||||
eval "set -- $(
|
||||
printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
|
||||
xargs -n1 |
|
||||
sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
|
||||
tr '\n' ' '
|
||||
)" '"$@"'
|
||||
|
||||
exec "$JAVACMD" "$@"
|
||||
Vendored
+89
@@ -0,0 +1,89 @@
|
||||
@rem
|
||||
@rem Copyright 2015 the original author or authors.
|
||||
@rem
|
||||
@rem Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@rem you may not use this file except in compliance with the License.
|
||||
@rem You may obtain a copy of the License at
|
||||
@rem
|
||||
@rem https://www.apache.org/licenses/LICENSE-2.0
|
||||
@rem
|
||||
@rem Unless required by applicable law or agreed to in writing, software
|
||||
@rem distributed under the License is distributed on an "AS IS" BASIS,
|
||||
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
@rem See the License for the specific language governing permissions and
|
||||
@rem limitations under the License.
|
||||
@rem
|
||||
|
||||
@if "%DEBUG%" == "" @echo off
|
||||
@rem ##########################################################################
|
||||
@rem
|
||||
@rem Gradle startup script for Windows
|
||||
@rem
|
||||
@rem ##########################################################################
|
||||
|
||||
@rem Set local scope for the variables with windows NT shell
|
||||
if "%OS%"=="Windows_NT" setlocal
|
||||
|
||||
set DIRNAME=%~dp0
|
||||
if "%DIRNAME%" == "" set DIRNAME=.
|
||||
set APP_BASE_NAME=%~n0
|
||||
set APP_HOME=%DIRNAME%
|
||||
|
||||
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
|
||||
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
|
||||
|
||||
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
|
||||
|
||||
@rem Find java.exe
|
||||
if defined JAVA_HOME goto findJavaFromJavaHome
|
||||
|
||||
set JAVA_EXE=java.exe
|
||||
%JAVA_EXE% -version >NUL 2>&1
|
||||
if "%ERRORLEVEL%" == "0" goto execute
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:findJavaFromJavaHome
|
||||
set JAVA_HOME=%JAVA_HOME:"=%
|
||||
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||
|
||||
if exist "%JAVA_EXE%" goto execute
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:execute
|
||||
@rem Setup the command line
|
||||
|
||||
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
||||
|
||||
|
||||
@rem Execute Gradle
|
||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
|
||||
|
||||
:end
|
||||
@rem End local scope for the variables with windows NT shell
|
||||
if "%ERRORLEVEL%"=="0" goto mainEnd
|
||||
|
||||
:fail
|
||||
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
||||
rem the _cmd.exe /c_ return code!
|
||||
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
|
||||
exit /b 1
|
||||
|
||||
:mainEnd
|
||||
if "%OS%"=="Windows_NT" endlocal
|
||||
|
||||
:omega
|
||||
@@ -0,0 +1,3 @@
|
||||
rootProject.name = "KSnippets"
|
||||
|
||||
include(":snippets-backend")
|
||||
@@ -0,0 +1,34 @@
|
||||
plugins {
|
||||
kotlin("multiplatform")
|
||||
kotlin("plugin.serialization")
|
||||
}
|
||||
|
||||
kotlin {
|
||||
listOf(
|
||||
linuxX64(),
|
||||
mingwX64()
|
||||
).forEach { it.binaries.executable { entryPoint = "snippets.main" } }
|
||||
|
||||
val ktorVersion = "3.5.2"
|
||||
|
||||
sourceSets {
|
||||
commonMain.dependencies {
|
||||
implementation("io.ktor:ktor-server-core:${ktorVersion}")
|
||||
implementation("io.ktor:ktor-server-cio:${ktorVersion}")
|
||||
implementation("io.ktor:ktor-server-content-negotiation:${ktorVersion}")
|
||||
implementation("io.ktor:ktor-serialization-kotlinx-json:${ktorVersion}")
|
||||
implementation("io.ktor:ktor-server-cors:${ktorVersion}")
|
||||
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.11.0")
|
||||
implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.8.0")
|
||||
implementation("org.jetbrains.kotlinx:kotlinx-io-core:0.9.1")
|
||||
}
|
||||
|
||||
linuxX64Main.dependencies {
|
||||
|
||||
}
|
||||
|
||||
mingwX64Main.dependencies {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
/*
|
||||
* Copyright © 2026 RTAkland
|
||||
* Author: RTAkland
|
||||
* Date: 2026/8/27
|
||||
*/
|
||||
|
||||
|
||||
package snippets
|
||||
|
||||
import kotlinx.io.files.Path
|
||||
import kotlinx.io.files.SystemFileSystem
|
||||
|
||||
val dataDir = Path("./data/snippets/")
|
||||
.apply { if (!SystemFileSystem.exists(this)) SystemFileSystem.createDirectories(this) }
|
||||
@@ -0,0 +1,16 @@
|
||||
/*
|
||||
* Copyright © 2026 RTAkland
|
||||
* Author: RTAkland
|
||||
* Date: 2026/8/27
|
||||
*/
|
||||
|
||||
|
||||
package snippets.data
|
||||
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
data class DirStats(
|
||||
val fileCount: Long,
|
||||
val totalBytes: Long,
|
||||
)
|
||||
@@ -0,0 +1,16 @@
|
||||
/*
|
||||
* Copyright © 2026 RTAkland
|
||||
* Author: RTAkland
|
||||
* Date: 2026/8/27
|
||||
*/
|
||||
|
||||
|
||||
package snippets.data
|
||||
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
data class SnippetContent(
|
||||
val content: String,
|
||||
val filename: String,
|
||||
)
|
||||
@@ -0,0 +1,18 @@
|
||||
/*
|
||||
* Copyright © 2026 RTAkland
|
||||
* Author: RTAkland
|
||||
* Date: 2026/8/27
|
||||
*/
|
||||
|
||||
|
||||
package snippets.data
|
||||
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlin.time.Instant
|
||||
|
||||
@Serializable
|
||||
data class SnippetMeta(
|
||||
val createdAt: Instant,
|
||||
val filename: String,
|
||||
val content: String,
|
||||
)
|
||||
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Copyright © 2026 RTAkland
|
||||
* Author: RTAkland
|
||||
* Date: 2026/8/27
|
||||
*/
|
||||
|
||||
|
||||
package snippets
|
||||
|
||||
import io.ktor.server.application.Application
|
||||
import io.ktor.server.cio.CIO
|
||||
import io.ktor.server.engine.embeddedServer
|
||||
import snippets.routing.registerSnippetsRouting
|
||||
import snippets.routing.registerStatusRouting
|
||||
|
||||
fun main() {
|
||||
embeddedServer(CIO, port = 6868, module = Application::module)
|
||||
.start(true)
|
||||
}
|
||||
|
||||
fun Application.module() {
|
||||
registerSnippetsRouting()
|
||||
registerStatusRouting()
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
* Copyright © 2026 RTAkland
|
||||
* Author: RTAkland
|
||||
* Date: 2026/8/27
|
||||
*/
|
||||
|
||||
|
||||
package snippets.routing
|
||||
|
||||
import io.ktor.http.*
|
||||
import io.ktor.serialization.kotlinx.json.*
|
||||
import io.ktor.server.application.*
|
||||
import io.ktor.server.plugins.contentnegotiation.*
|
||||
import io.ktor.server.plugins.cors.routing.*
|
||||
import io.ktor.server.request.*
|
||||
import io.ktor.server.response.*
|
||||
import io.ktor.server.routing.*
|
||||
import io.ktor.utils.io.core.*
|
||||
import kotlinx.io.Buffer
|
||||
import kotlinx.io.buffered
|
||||
import kotlinx.io.files.Path
|
||||
import kotlinx.io.files.SystemFileSystem
|
||||
import kotlinx.io.readString
|
||||
import snippets.data.SnippetContent
|
||||
import snippets.data.SnippetMeta
|
||||
import snippets.dataDir
|
||||
import snippets.util.encodeJson
|
||||
import snippets.util.fromJson
|
||||
import kotlin.time.Clock
|
||||
|
||||
fun Application.registerSnippetsRouting() {
|
||||
install(ContentNegotiation) {
|
||||
json()
|
||||
}
|
||||
|
||||
install(CORS) {
|
||||
allowMethod(HttpMethod.Options)
|
||||
allowMethod(HttpMethod.Get)
|
||||
allowMethod(HttpMethod.Post)
|
||||
allowMethod(HttpMethod.Put)
|
||||
allowMethod(HttpMethod.Delete)
|
||||
|
||||
allowHeader(HttpHeaders.ContentType)
|
||||
allowHeader(HttpHeaders.Authorization)
|
||||
allowHeader(HttpHeaders.AccessControlAllowOrigin)
|
||||
|
||||
anyHost()
|
||||
}
|
||||
|
||||
routing {
|
||||
post("/api/v1/snippets") {
|
||||
val payload = call.receive<SnippetContent>()
|
||||
val snippetId = generateShortId()
|
||||
val meta = SnippetMeta(Clock.System.now(), payload.filename, payload.content)
|
||||
.encodeJson().toByteArray()
|
||||
val snippetPath = Path(dataDir, snippetId).apply { SystemFileSystem.createDirectories(this) }
|
||||
SystemFileSystem.sink(Path(snippetPath, "meta.json")).use {
|
||||
val buffer = Buffer().apply { write(meta) }
|
||||
it.write(buffer, meta.size.toLong())
|
||||
}
|
||||
call.respond(status = HttpStatusCode.Created, message = mapOf("snippet_id" to snippetId))
|
||||
}
|
||||
|
||||
get("/{snippetId}") {
|
||||
val mode = call.queryParameters["mode"] ?: "serialized"
|
||||
val snippetId = call.parameters["snippetId"] ?: return@get call.respond(HttpStatusCode.BadRequest)
|
||||
val snippetPath = Path(dataDir, snippetId)
|
||||
|
||||
if (!SystemFileSystem.exists(snippetPath)) {
|
||||
call.respond(HttpStatusCode.NotFound)
|
||||
return@get
|
||||
}
|
||||
|
||||
val meta = SystemFileSystem.source(Path(snippetPath, "meta.json"))
|
||||
.use { it.buffered().readString().fromJson<SnippetMeta>() }
|
||||
if (mode == "raw") call.respond(meta.content) else call.respond(meta)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun generateShortId(length: Int = 6): String {
|
||||
val charPool = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
|
||||
return (1..length)
|
||||
.map { charPool.random() }
|
||||
.joinToString("")
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright © 2026 RTAkland
|
||||
* Author: RTAkland
|
||||
* Date: 2026/8/27
|
||||
*/
|
||||
|
||||
|
||||
package snippets.routing
|
||||
|
||||
import io.ktor.http.HttpStatusCode
|
||||
import io.ktor.server.application.*
|
||||
import io.ktor.server.response.respond
|
||||
import io.ktor.server.routing.*
|
||||
import kotlinx.io.files.Path
|
||||
import kotlinx.io.files.SystemFileSystem
|
||||
import snippets.data.DirStats
|
||||
import snippets.dataDir
|
||||
|
||||
fun Application.registerStatusRouting() {
|
||||
routing {
|
||||
get("/api/v1/status") {
|
||||
call.respond(HttpStatusCode.OK, getDirStats(dataDir))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun getDirStats(dirPath: Path): DirStats {
|
||||
if (!SystemFileSystem.exists(dirPath)) return DirStats(0, 0)
|
||||
var count = 0L
|
||||
var bytes = 0L
|
||||
SystemFileSystem.list(dirPath).forEach { path ->
|
||||
val metadata = SystemFileSystem.metadataOrNull(path) ?: return@forEach
|
||||
when {
|
||||
metadata.isRegularFile -> {
|
||||
count++
|
||||
bytes += metadata.size
|
||||
}
|
||||
|
||||
metadata.isDirectory -> {
|
||||
val subStats = getDirStats(path)
|
||||
count += subStats.fileCount
|
||||
bytes += subStats.totalBytes
|
||||
}
|
||||
}
|
||||
}
|
||||
return DirStats(count, bytes)
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Copyright © 2026 RTAkland
|
||||
* Author: RTAkland
|
||||
* Date: 2026/8/27
|
||||
*/
|
||||
|
||||
|
||||
package snippets.util
|
||||
|
||||
import kotlinx.serialization.json.Json
|
||||
|
||||
val json: Json = Json {
|
||||
ignoreUnknownKeys = true
|
||||
explicitNulls = false
|
||||
classDiscriminator = "_json_type_"
|
||||
encodeDefaults = true
|
||||
coerceInputValues = true
|
||||
decodeEnumsCaseInsensitive = true
|
||||
isLenient = true
|
||||
}
|
||||
|
||||
inline fun <reified T> T.encodeJson(): String {
|
||||
return json.encodeToString(this)
|
||||
}
|
||||
|
||||
inline fun <reified T> String.fromJson(): T {
|
||||
return json.decodeFromString<T>(this)
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
# v0 sandbox internal files
|
||||
__v0_runtime_loader.js
|
||||
__v0_devtools.tsx
|
||||
__v0_jsx-dev-runtime.ts
|
||||
.snowflake/
|
||||
.v0-trash/
|
||||
.vercel/
|
||||
|
||||
# Environment variables
|
||||
.env*.local
|
||||
|
||||
# Common ignores
|
||||
node_modules
|
||||
.next/
|
||||
.DS_Store
|
||||
@@ -0,0 +1,67 @@
|
||||
import Link from 'next/link'
|
||||
import {ArrowLeft, ArrowUpRight, FileCode2, RefreshCw, Terminal} from 'lucide-react'
|
||||
import {languageLabel, rawSnippetUrl} from '@/lib/snippet-utils'
|
||||
import {SnippetEditor} from '@/components/snippet-editor'
|
||||
|
||||
const API_BASE = 'http://127.0.0.1:6868'
|
||||
|
||||
type Snippet = { createdAt?: string; filename: string; content: string }
|
||||
|
||||
async function getSnippet(id: string): Promise<{ data?: Snippet; status: number }> {
|
||||
try {
|
||||
const response = await fetch(`${API_BASE}/${encodeURIComponent(id)}`, {cache: 'no-store'})
|
||||
if (!response.ok) return {status: response.status}
|
||||
return {data: await response.json(), status: response.status}
|
||||
} catch {
|
||||
return {status: 503}
|
||||
}
|
||||
}
|
||||
|
||||
export default async function ReaderPage({params}: { params: Promise<{ snippet_id: string }> }) {
|
||||
const {snippet_id: id} = await params
|
||||
const result = await getSnippet(id)
|
||||
const snippet = result.data
|
||||
const message = result.status === 404 ? 'This snippet does not exist or has expired.' : 'The snippet server could not be reached.'
|
||||
|
||||
return (
|
||||
<main className="min-h-screen bg-background text-foreground">
|
||||
<header className="border-b border-border">
|
||||
<div className="mx-auto flex max-w-6xl items-center justify-between px-5 py-4 lg:px-8"><Link href="/"
|
||||
className="flex items-center gap-3 font-mono text-sm font-semibold tracking-tight"><span
|
||||
className="grid size-8 place-items-center rounded-lg bg-primary text-primary-foreground"><Terminal
|
||||
size={16}/></span>KSnippets</Link><Link href="/"
|
||||
className="inline-flex items-center gap-2 text-xs text-muted-foreground hover:text-foreground"><ArrowLeft
|
||||
size={14}/> New snippet</Link></div>
|
||||
</header>
|
||||
<div className="mx-auto max-w-6xl px-5 py-10 lg:px-8 lg:py-16">
|
||||
{snippet ? <>
|
||||
<div className="mb-8 flex flex-col gap-4 sm:flex-row sm:items-end sm:justify-between">
|
||||
<div><p className="mb-3 font-mono text-xs uppercase tracking-[0.2em] text-brand">snippet / <em>{id}</em></p><h1
|
||||
className="flex items-center gap-3 text-3xl font-semibold tracking-[-0.03em]">
|
||||
<FileCode2 size={25} className="text-brand"/>{snippet.filename}</h1><p
|
||||
className="mt-3 text-sm text-muted-foreground">{snippet.createdAt ? new Date(snippet.createdAt).toLocaleString() : 'Published snippet'}
|
||||
<span className="mx-2 text-border">·</span> <span
|
||||
className="font-mono">{languageLabel(snippet.filename)}</span></p></div>
|
||||
<a href={rawSnippetUrl(id)} target="_blank" rel="noreferrer"
|
||||
className="inline-flex w-fit items-center gap-2 rounded-lg border border-border bg-card px-4 py-2.5 text-sm font-medium hover:bg-muted">Open
|
||||
raw <ArrowUpRight size={15}/></a></div>
|
||||
<SnippetEditor value={snippet.content} filename={snippet.filename} readOnly/>
|
||||
<div
|
||||
className="mt-4 font-mono text-xs text-muted-foreground">{snippet.content.split('\n').length} lines
|
||||
</div>
|
||||
</> : <div className="mx-auto max-w-lg py-16 text-center">
|
||||
<div
|
||||
className="mx-auto mb-5 grid size-14 place-items-center rounded-2xl bg-muted text-muted-foreground">{result.status === 404 ? '404' :
|
||||
<RefreshCw size={22}/>}</div>
|
||||
<h1 className="text-2xl font-semibold tracking-tight">{result.status === 404 ? 'Snippet not found' : 'Connection error'}</h1>
|
||||
<p className="mt-3 leading-6 text-muted-foreground">{message}</p>
|
||||
<div className="mt-7 flex justify-center gap-3"><Link href="/"
|
||||
className="rounded-lg bg-primary px-4 py-2.5 text-sm font-medium text-primary-foreground">Create
|
||||
a snippet</Link>{result.status !== 404 && <a href={`/${id}`}
|
||||
className="rounded-lg border border-border px-4 py-2.5 text-sm font-medium hover:bg-muted">Try
|
||||
again</a>}</div>
|
||||
</div>}
|
||||
</div>
|
||||
</main>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
@import 'tailwindcss';
|
||||
@import 'tw-animate-css';
|
||||
@import 'shadcn/tailwind.css';
|
||||
|
||||
@custom-variant dark (&:is(.dark *));
|
||||
|
||||
@theme inline {
|
||||
--font-sans: 'Geist', 'Geist Fallback';
|
||||
--font-mono: 'Geist Mono', 'Geist Mono Fallback';
|
||||
--color-background: var(--background);
|
||||
--color-foreground: var(--foreground);
|
||||
--color-card: var(--card);
|
||||
--color-card-foreground: var(--card-foreground);
|
||||
--color-primary: var(--primary);
|
||||
--color-primary-foreground: var(--primary-foreground);
|
||||
--color-muted: var(--muted);
|
||||
--color-muted-foreground: var(--muted-foreground);
|
||||
--color-border: var(--border);
|
||||
--color-destructive: var(--destructive);
|
||||
--color-brand: var(--brand);
|
||||
--color-editor: var(--editor);
|
||||
--radius-lg: 0.75rem;
|
||||
}
|
||||
|
||||
:root {
|
||||
color-scheme: light;
|
||||
--background: oklch(0.975 0.008 90);
|
||||
--foreground: oklch(0.19 0.025 250);
|
||||
--card: oklch(1 0 0);
|
||||
--primary: oklch(0.22 0.035 250);
|
||||
--primary-foreground: oklch(0.98 0.008 90);
|
||||
--muted: oklch(0.94 0.012 90);
|
||||
--muted-foreground: oklch(0.49 0.025 250);
|
||||
--border: oklch(0.88 0.018 90);
|
||||
--destructive: oklch(0.58 0.19 25);
|
||||
--brand: oklch(0.68 0.14 153);
|
||||
--editor: oklch(0.17 0.025 250);
|
||||
}
|
||||
|
||||
* { @apply border-border; }
|
||||
html { background: var(--background); }
|
||||
body { @apply bg-background text-foreground font-sans antialiased; }
|
||||
button, a, input { transition: color 160ms ease, background-color 160ms ease, border-color 160ms ease, opacity 160ms ease; }
|
||||
.snippet-codemirror .cm-editor { font-family: var(--font-geist-mono), ui-monospace, monospace; }
|
||||
.snippet-codemirror .cm-scroller { padding: 12px 0; }
|
||||
@@ -0,0 +1,28 @@
|
||||
import {Analytics} from '@vercel/analytics/next'
|
||||
import {Geist, Geist_Mono} from 'next/font/google'
|
||||
import type {Metadata, Viewport} from 'next'
|
||||
import './globals.css'
|
||||
|
||||
const geist = Geist({subsets: ['latin'], variable: '--font-geist-sans'})
|
||||
const geistMono = Geist_Mono({subsets: ['latin'], variable: '--font-geist-mono'})
|
||||
|
||||
export const metadata: Metadata = {
|
||||
title: 'KSnippets',
|
||||
description: 'Snippets for RTAST',
|
||||
icons: [
|
||||
{url: '/icon.svg'}
|
||||
],
|
||||
}
|
||||
|
||||
export const viewport: Viewport = {
|
||||
colorScheme: 'light',
|
||||
themeColor: '#f8f7f2',
|
||||
userScalable: true,
|
||||
}
|
||||
|
||||
export default function RootLayout({children}: Readonly<{ children: React.ReactNode }>) {
|
||||
return <html lang="en" className="bg-background">
|
||||
<body className={`${geist.variable} ${geistMono.variable}`}>{children}{process.env.NODE_ENV === 'production' &&
|
||||
<Analytics/>}</body>
|
||||
</html>
|
||||
}
|
||||
@@ -0,0 +1,147 @@
|
||||
'use client'
|
||||
|
||||
import {FormEvent, useState} from 'react'
|
||||
import {ArrowUpRight, Check, Copy, FileCode2, Loader2, Send, Terminal, X} from 'lucide-react'
|
||||
import {languageLabel, rawSnippetUrl, SnippetEditor, snippetUrl} from '@/components/snippet-editor'
|
||||
|
||||
const API_BASE = 'http://127.0.0.1:6868'
|
||||
|
||||
async function copyToClipboard(text: string) {
|
||||
if (navigator.clipboard && window.isSecureContext) {
|
||||
try {
|
||||
await navigator.clipboard.writeText(text);
|
||||
return true;
|
||||
} catch (err) {
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
const textArea = document.createElement('textarea');
|
||||
textArea.value = text;
|
||||
|
||||
textArea.style.position = 'fixed';
|
||||
textArea.style.left = '-999999px';
|
||||
textArea.style.top = '-999999px';
|
||||
document.body.appendChild(textArea);
|
||||
|
||||
textArea.focus();
|
||||
textArea.select();
|
||||
|
||||
const successful = document.execCommand('copy');
|
||||
document.body.removeChild(textArea);
|
||||
|
||||
if (!successful) throw new Error('execCommand copy failed');
|
||||
return true;
|
||||
} catch (err) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
export default function Page() {
|
||||
const [content, setContent] = useState('')
|
||||
const [filename, setFilename] = useState('untitled.txt')
|
||||
const [snippetId, setSnippetId] = useState('')
|
||||
const [status, setStatus] = useState<'idle' | 'loading' | 'error'>('idle')
|
||||
const [error, setError] = useState('')
|
||||
const [copied, setCopied] = useState(false)
|
||||
|
||||
async function submit(event: FormEvent) {
|
||||
event.preventDefault()
|
||||
if (!content.trim()) {
|
||||
setError('Add some content before publishing.');
|
||||
setStatus('error');
|
||||
return
|
||||
}
|
||||
setStatus('loading');
|
||||
setError('');
|
||||
setSnippetId('')
|
||||
try {
|
||||
const response = await fetch(`${API_BASE}/api/v1/snippets`, {
|
||||
method: 'POST',
|
||||
headers: {'Content-Type': 'application/json'},
|
||||
body: JSON.stringify({content, filename})
|
||||
})
|
||||
if (!response.ok) throw new Error(`Request failed with ${response.status}`)
|
||||
const data = await response.json()
|
||||
if (!data.snippet_id) throw new Error('The server did not return a snippet_id.')
|
||||
setSnippetId(data.snippet_id);
|
||||
setStatus('idle')
|
||||
} catch (caught) {
|
||||
setStatus('error');
|
||||
setError(caught instanceof Error ? caught.message : 'Could not reach the snippet server.')
|
||||
}
|
||||
}
|
||||
|
||||
async function copyLink() {
|
||||
if (!snippetId) return
|
||||
await copyToClipboard(snippetUrl(snippetId));
|
||||
setCopied(true);
|
||||
window.setTimeout(() => setCopied(false), 1600)
|
||||
}
|
||||
|
||||
function reset() {
|
||||
setContent('');
|
||||
setFilename('untitled.txt');
|
||||
setSnippetId('');
|
||||
setError('');
|
||||
setStatus('idle')
|
||||
}
|
||||
|
||||
return (
|
||||
<main className="min-h-screen bg-background text-foreground">
|
||||
<header className="border-b border-border">
|
||||
<div className="mx-auto flex max-w-6xl items-center justify-between px-5 py-4 lg:px-8">
|
||||
<a href="/" className="flex items-center gap-3 font-mono text-sm font-semibold tracking-tight"><span
|
||||
className="grid size-8 place-items-center rounded-lg bg-primary text-primary-foreground"><Terminal
|
||||
size={16}/></span>KSnippets</a>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<div className="mx-auto max-w-6xl px-5 py-10 lg:px-8 lg:py-16">
|
||||
<form onSubmit={submit}>
|
||||
<div className="mb-3 flex flex-wrap items-center justify-between gap-3">
|
||||
<div className="flex items-center gap-2 text-sm font-medium"><FileCode2 size={16}
|
||||
className="text-brand"/> New
|
||||
snippet
|
||||
</div>
|
||||
<div className="flex items-center gap-2"><span
|
||||
className="rounded-md bg-muted px-2.5 py-1 font-mono text-[11px] text-muted-foreground">{languageLabel(filename)}</span>
|
||||
<button type="button" onClick={reset}
|
||||
className="rounded-md p-1.5 text-muted-foreground hover:bg-muted hover:text-foreground"
|
||||
aria-label="Clear editor"><X size={15}/></button>
|
||||
</div>
|
||||
</div>
|
||||
<SnippetEditor value={content} filename={filename} onChange={setContent}/>
|
||||
<div className="mt-4 flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between"><label
|
||||
className="flex items-center gap-3 text-sm text-muted-foreground"><span
|
||||
className="font-mono text-xs">filename</span><input value={filename}
|
||||
onChange={(event) => setFilename(event.target.value || 'untitled.txt')}
|
||||
className="w-44 border-b border-border bg-transparent py-1 text-foreground outline-none focus:border-brand"/></label>
|
||||
<button disabled={status === 'loading'}
|
||||
className="inline-flex items-center justify-center gap-2 rounded-lg bg-primary px-5 py-2.5 text-sm font-medium text-primary-foreground transition hover:bg-primary/90 disabled:cursor-wait disabled:opacity-70">{status === 'loading' ?
|
||||
<Loader2 size={16} className="animate-spin"/> : <Send size={16}/>} Publish snippet
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
{status === 'error' && <div role="alert"
|
||||
className="mt-5 rounded-lg border border-destructive/30 bg-destructive/10 px-4 py-3 text-sm text-destructive">{error}</div>}
|
||||
{snippetId && <section className="mt-8 rounded-xl border border-brand/30 bg-brand/5 p-5">
|
||||
<div className="flex flex-col gap-4 sm:flex-row sm:items-center sm:justify-between">
|
||||
<div><p className="mb-1 text-xs font-medium uppercase tracking-widest text-brand">published
|
||||
successfully</p><a href={`/${snippetId}`}
|
||||
className="font-mono text-sm text-foreground underline decoration-brand underline-offset-4">/{snippetId}</a>
|
||||
</div>
|
||||
<div className="flex flex-wrap gap-2">
|
||||
<button type="button" onClick={copyLink}
|
||||
className="inline-flex items-center gap-2 rounded-lg border border-border bg-background px-3 py-2 text-xs font-medium hover:bg-muted">{copied ?
|
||||
<Check size={14}/> : <Copy size={14}/>}{copied ? 'Copied' : 'Copy link'}</button>
|
||||
<a href={rawSnippetUrl(snippetId)} target="_blank" rel="noreferrer"
|
||||
className="inline-flex items-center gap-2 rounded-lg bg-primary px-3 py-2 text-xs font-medium text-primary-foreground">Raw <ArrowUpRight
|
||||
size={14}/></a></div>
|
||||
</div>
|
||||
</section>}
|
||||
</div>
|
||||
</main>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"$schema": "https://ui.shadcn.com/schema.json",
|
||||
"style": "base-nova",
|
||||
"rsc": true,
|
||||
"tsx": true,
|
||||
"tailwind": {
|
||||
"config": "",
|
||||
"css": "app/globals.css",
|
||||
"baseColor": "neutral",
|
||||
"cssVariables": true,
|
||||
"prefix": ""
|
||||
},
|
||||
"aliases": {
|
||||
"components": "@/components",
|
||||
"utils": "@/lib/utils",
|
||||
"ui": "@/components/ui",
|
||||
"lib": "@/lib",
|
||||
"hooks": "@/hooks"
|
||||
},
|
||||
"iconLibrary": "lucide"
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
'use client'
|
||||
|
||||
import { useMemo } from 'react'
|
||||
import CodeMirror from '@uiw/react-codemirror'
|
||||
import { javascript } from '@codemirror/lang-javascript'
|
||||
import { json } from '@codemirror/lang-json'
|
||||
import { markdown } from '@codemirror/lang-markdown'
|
||||
import { python } from '@codemirror/lang-python'
|
||||
import { rust } from '@codemirror/lang-rust'
|
||||
import { sql } from '@codemirror/lang-sql'
|
||||
import { xml } from '@codemirror/lang-xml'
|
||||
import { css } from '@codemirror/lang-css'
|
||||
import { go } from '@codemirror/lang-go'
|
||||
import { java } from '@codemirror/lang-java'
|
||||
import { cpp } from '@codemirror/lang-cpp'
|
||||
import { yaml } from '@codemirror/lang-yaml'
|
||||
import { oneDark } from '@codemirror/theme-one-dark'
|
||||
|
||||
type Props = {
|
||||
value: string
|
||||
filename: string
|
||||
onChange?: (value: string) => void
|
||||
readOnly?: boolean
|
||||
}
|
||||
|
||||
function languageFor(filename: string) {
|
||||
const extension = filename.split('.').pop()?.toLowerCase()
|
||||
if (!extension) return null
|
||||
if (['js', 'jsx', 'ts', 'tsx', 'mjs', 'cjs'].includes(extension)) {
|
||||
return javascript({ jsx: true, typescript: extension.includes('ts') })
|
||||
}
|
||||
if (['html', 'xml', 'svg'].includes(extension)) return xml()
|
||||
if (['css', 'scss', 'less'].includes(extension)) return css()
|
||||
if (extension === 'go') return go()
|
||||
if (['java', 'kt', 'kts'].includes(extension)) return java()
|
||||
if (['c', 'cpp', 'cc', 'cxx', 'h', 'hpp', 'cs'].includes(extension)) return cpp()
|
||||
if (['yaml', 'yml'].includes(extension)) return yaml()
|
||||
if (extension === 'json') return json()
|
||||
if (['md', 'markdown'].includes(extension)) return markdown()
|
||||
if (extension === 'py') return python()
|
||||
if (extension === 'rs') return rust()
|
||||
if (extension === 'sql') return sql()
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
export function SnippetEditor({ value, filename, onChange, readOnly = false }: Props) {
|
||||
const extensions = useMemo(() => {
|
||||
const language = languageFor(filename)
|
||||
return language ? [language] : []
|
||||
}, [filename])
|
||||
|
||||
return (
|
||||
<div className="overflow-hidden rounded-xl border border-border bg-editor shadow-sm">
|
||||
<CodeMirror
|
||||
value={value}
|
||||
height="min(58vh, 560px)"
|
||||
extensions={extensions}
|
||||
theme={oneDark}
|
||||
onChange={onChange}
|
||||
readOnly={readOnly}
|
||||
basicSetup={{
|
||||
lineNumbers: true,
|
||||
foldGutter: true,
|
||||
highlightActiveLine: !readOnly,
|
||||
autocompletion: !readOnly
|
||||
}}
|
||||
className="snippet-codemirror font-mono text-sm"
|
||||
aria-label={readOnly ? 'Snippet content' : 'Snippet editor'}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export function languageLabel(filename: string) {
|
||||
const extension = filename.split('.').pop()?.toUpperCase()
|
||||
return extension && extension.length <= 6 ? extension : 'TEXT'
|
||||
}
|
||||
|
||||
export function rawSnippetUrl(id: string) {
|
||||
return `http://127.0.0.1:6868/${encodeURIComponent(id)}?mode=raw`
|
||||
}
|
||||
|
||||
export function snippetUrl(id: string) {
|
||||
if (typeof window === 'undefined') return `/${encodeURIComponent(id)}`
|
||||
return new URL(`/${encodeURIComponent(id)}`, window.location.origin).toString()
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
import { Button as ButtonPrimitive } from '@base-ui/react/button'
|
||||
import { cva, type VariantProps } from 'class-variance-authority'
|
||||
|
||||
import { cn } from '@/lib/utils'
|
||||
|
||||
const buttonVariants = cva(
|
||||
"group/button inline-flex shrink-0 items-center justify-center rounded-lg border border-transparent bg-clip-padding text-sm font-medium whitespace-nowrap transition-all outline-none select-none focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 active:not-aria-[haspopup]:translate-y-px disabled:pointer-events-none disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
||||
{
|
||||
variants: {
|
||||
variant: {
|
||||
default: 'bg-primary text-primary-foreground [a]:hover:bg-primary/80',
|
||||
outline:
|
||||
'border-border bg-background hover:bg-muted hover:text-foreground aria-expanded:bg-muted aria-expanded:text-foreground dark:border-input dark:bg-input/30 dark:hover:bg-input/50',
|
||||
secondary:
|
||||
'bg-secondary text-secondary-foreground hover:bg-secondary/80 aria-expanded:bg-secondary aria-expanded:text-secondary-foreground',
|
||||
ghost:
|
||||
'hover:bg-muted hover:text-foreground aria-expanded:bg-muted aria-expanded:text-foreground dark:hover:bg-muted/50',
|
||||
destructive:
|
||||
'bg-destructive/10 text-destructive hover:bg-destructive/20 focus-visible:border-destructive/40 focus-visible:ring-destructive/20 dark:bg-destructive/20 dark:hover:bg-destructive/30 dark:focus-visible:ring-destructive/40',
|
||||
link: 'text-primary underline-offset-4 hover:underline',
|
||||
},
|
||||
size: {
|
||||
default:
|
||||
'h-8 gap-1.5 px-2.5 has-data-[icon=inline-end]:pr-2 has-data-[icon=inline-start]:pl-2',
|
||||
xs: "h-6 gap-1 rounded-[min(var(--radius-md),10px)] px-2 text-xs in-data-[slot=button-group]:rounded-lg has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5 [&_svg:not([class*='size-'])]:size-3",
|
||||
sm: "h-7 gap-1 rounded-[min(var(--radius-md),12px)] px-2.5 text-[0.8rem] in-data-[slot=button-group]:rounded-lg has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5 [&_svg:not([class*='size-'])]:size-3.5",
|
||||
lg: 'h-9 gap-1.5 px-2.5 has-data-[icon=inline-end]:pr-2 has-data-[icon=inline-start]:pl-2',
|
||||
icon: 'size-8',
|
||||
'icon-xs':
|
||||
"size-6 rounded-[min(var(--radius-md),10px)] in-data-[slot=button-group]:rounded-lg [&_svg:not([class*='size-'])]:size-3",
|
||||
'icon-sm':
|
||||
'size-7 rounded-[min(var(--radius-md),12px)] in-data-[slot=button-group]:rounded-lg',
|
||||
'icon-lg': 'size-9',
|
||||
},
|
||||
},
|
||||
defaultVariants: {
|
||||
variant: 'default',
|
||||
size: 'default',
|
||||
},
|
||||
},
|
||||
)
|
||||
|
||||
function Button({
|
||||
className,
|
||||
variant = 'default',
|
||||
size = 'default',
|
||||
...props
|
||||
}: ButtonPrimitive.Props & VariantProps<typeof buttonVariants>) {
|
||||
return (
|
||||
<ButtonPrimitive
|
||||
data-slot="button"
|
||||
className={cn(buttonVariants({ variant, size, className }))}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export { Button, buttonVariants }
|
||||
@@ -0,0 +1,13 @@
|
||||
export function languageLabel(filename: string) {
|
||||
const extension = filename.split('.').pop()?.toUpperCase()
|
||||
return extension && extension.length <= 6 ? extension : 'TEXT'
|
||||
}
|
||||
|
||||
export function rawSnippetUrl(id: string) {
|
||||
return `http://127.0.0.1:6868/${encodeURIComponent(id)}?mode=raw`
|
||||
}
|
||||
|
||||
export function snippetUrl(id: string) {
|
||||
if (typeof window === 'undefined') return `/${encodeURIComponent(id)}`
|
||||
return new URL(`/${encodeURIComponent(id)}`, window.location.origin).toString()
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
import { clsx, type ClassValue } from 'clsx'
|
||||
import { twMerge } from 'tailwind-merge'
|
||||
|
||||
export function cn(...inputs: ClassValue[]) {
|
||||
return twMerge(clsx(inputs))
|
||||
}
|
||||
Vendored
+7
@@ -0,0 +1,7 @@
|
||||
/// <reference types="next" />
|
||||
/// <reference types="next/image-types/global" />
|
||||
import "./.next/dev/types/routes.d.ts";
|
||||
import "./.next/dev/types/root-params.d.ts";
|
||||
|
||||
// NOTE: This file should not be edited
|
||||
// see https://nextjs.org/docs/app/api-reference/config/typescript for more information.
|
||||
@@ -0,0 +1,14 @@
|
||||
/** @type {import('next').NextConfig} */
|
||||
const nextConfig = {
|
||||
typescript: {
|
||||
ignoreBuildErrors: true,
|
||||
},
|
||||
images: {
|
||||
unoptimized: true,
|
||||
},
|
||||
allowedDevOrigins: [
|
||||
"192.168.10.101"
|
||||
]
|
||||
}
|
||||
|
||||
export default nextConfig
|
||||
@@ -0,0 +1,46 @@
|
||||
{
|
||||
"name": "my-project",
|
||||
"version": "0.1.0",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"dev": "next dev",
|
||||
"build": "next build",
|
||||
"start": "next start"
|
||||
},
|
||||
"dependencies": {
|
||||
"@base-ui/react": "^1.5.0",
|
||||
"@codemirror/lang-cpp": "^6.0.3",
|
||||
"@codemirror/lang-css": "^6.3.1",
|
||||
"@codemirror/lang-go": "^6.0.1",
|
||||
"@codemirror/lang-java": "^6.0.2",
|
||||
"@codemirror/lang-javascript": "^6.2.5",
|
||||
"@codemirror/lang-json": "^6.0.2",
|
||||
"@codemirror/lang-markdown": "^6.5.2",
|
||||
"@codemirror/lang-python": "^6.2.1",
|
||||
"@codemirror/lang-rust": "^6.0.2",
|
||||
"@codemirror/lang-sql": "^6.10.0",
|
||||
"@codemirror/lang-xml": "^6.1.0",
|
||||
"@codemirror/lang-yaml": "^6.1.3",
|
||||
"@codemirror/theme-one-dark": "^6.1.3",
|
||||
"@uiw/react-codemirror": "^4.25.11",
|
||||
"@vercel/analytics": "1.6.1",
|
||||
"class-variance-authority": "^0.7.1",
|
||||
"clsx": "^2.1.1",
|
||||
"lucide-react": "^1.16.0",
|
||||
"next": "16.3.3",
|
||||
"react": "^19",
|
||||
"react-dom": "^19",
|
||||
"shadcn": "^4.11.0",
|
||||
"tailwind-merge": "^3.3.1",
|
||||
"tw-animate-css": "^1.4.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@tailwindcss/postcss": "^4.3.3",
|
||||
"@types/node": "^24",
|
||||
"@types/react": "^19",
|
||||
"@types/react-dom": "^19",
|
||||
"postcss": "^8.5",
|
||||
"tailwindcss": "^4.3.3",
|
||||
"typescript": "5.7.3"
|
||||
}
|
||||
}
|
||||
Generated
+3961
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,3 @@
|
||||
minimumReleaseAgeExclude:
|
||||
- '@next/*'
|
||||
- next
|
||||
@@ -0,0 +1,8 @@
|
||||
/** @type {import('postcss-load-config').Config} */
|
||||
const config = {
|
||||
plugins: {
|
||||
'@tailwindcss/postcss': {},
|
||||
},
|
||||
}
|
||||
|
||||
export default config
|
||||
@@ -0,0 +1,5 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor"
|
||||
stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-terminal" aria-hidden="true">
|
||||
<path d="M12 19h8"></path>
|
||||
<path d="m4 17 6-6-6-6"></path>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 310 B |
@@ -0,0 +1,33 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"lib": ["dom", "dom.iterable", "esnext"],
|
||||
"allowJs": true,
|
||||
"target": "ES6",
|
||||
"skipLibCheck": true,
|
||||
"strict": true,
|
||||
"noEmit": true,
|
||||
"esModuleInterop": true,
|
||||
"module": "esnext",
|
||||
"moduleResolution": "bundler",
|
||||
"resolveJsonModule": true,
|
||||
"isolatedModules": true,
|
||||
"jsx": "react-jsx",
|
||||
"incremental": true,
|
||||
"plugins": [
|
||||
{
|
||||
"name": "next"
|
||||
}
|
||||
],
|
||||
"paths": {
|
||||
"@/*": ["./*"]
|
||||
}
|
||||
},
|
||||
"include": [
|
||||
"next-env.d.ts",
|
||||
"**/*.ts",
|
||||
"**/*.tsx",
|
||||
".next/types/**/*.ts",
|
||||
".next/dev/types/**/*.ts"
|
||||
],
|
||||
"exclude": ["node_modules"]
|
||||
}
|
||||
Reference in New Issue
Block a user