feat(depot): initial work for depot

This commit is contained in:
reya 2023-12-15 09:15:30 +07:00
parent 591373fd52
commit ba93bdbb91
14 changed files with 902 additions and 489 deletions

3
.gitmodules vendored Normal file
View File

@ -0,0 +1,3 @@
[submodule "modules/depot"]
path = modules/depot
url = https://github.com/luminous-devs/depot.git

1
modules/depot Submodule

@ -0,0 +1 @@
Subproject commit 22f913f26ff365c6408b005b695200279586211f

View File

@ -20,7 +20,7 @@
"dependencies": {
"@evilmartians/harmony": "^1.2.0",
"@getalby/sdk": "^2.7.0",
"@nostr-dev-kit/ndk": "^2.2.0",
"@nostr-dev-kit/ndk": "^2.3.0",
"@nostr-fetch/adapter-ndk": "^0.13.1",
"@radix-ui/react-accordion": "^1.1.2",
"@radix-ui/react-alert-dialog": "^1.0.5",
@ -34,7 +34,7 @@
"@radix-ui/react-toolbar": "^1.0.4",
"@radix-ui/react-tooltip": "^1.0.7",
"@tanstack/react-query": "^5.13.4",
"@tanstack/react-query-devtools": "^5.13.4",
"@tanstack/react-query-devtools": "^5.13.5",
"@tauri-apps/api": "2.0.0-alpha.11",
"@tauri-apps/cli": "2.0.0-alpha.17",
"@tauri-apps/plugin-autostart": "2.0.0-alpha.3",
@ -60,7 +60,7 @@
"@tiptap/react": "^2.1.13",
"@tiptap/starter-kit": "^2.1.13",
"@tiptap/suggestion": "^2.1.13",
"@vidstack/react": "^1.9.3",
"@vidstack/react": "^1.9.7",
"dayjs": "^1.11.10",
"framer-motion": "^10.16.16",
"html-to-text": "^9.0.5",
@ -76,13 +76,14 @@
"react": "^18.2.0",
"react-currency-input-field": "^3.6.12",
"react-dom": "^18.2.0",
"react-hook-form": "^7.49.0",
"react-hook-form": "^7.49.2",
"react-hotkeys-hook": "^4.4.1",
"react-router-dom": "^6.21.0",
"react-string-replace": "^1.1.1",
"sonner": "^1.2.4",
"tippy.js": "^6.3.7",
"tiptap-markdown": "^0.8.8",
"use-react-workers": "^0.3.0",
"virtua": "^0.17.5"
},
"devDependencies": {
@ -91,10 +92,10 @@
"@trivago/prettier-plugin-sort-imports": "^4.3.0",
"@types/html-to-text": "^9.0.4",
"@types/node": "^20.10.4",
"@types/react": "^18.2.43",
"@types/react": "^18.2.45",
"@types/react-dom": "^18.2.17",
"@typescript-eslint/eslint-plugin": "^6.13.2",
"@typescript-eslint/parser": "^6.13.2",
"@typescript-eslint/eslint-plugin": "^6.14.0",
"@typescript-eslint/parser": "^6.14.0",
"@vitejs/plugin-react-swc": "^3.5.0",
"autoprefixer": "^10.4.16",
"clsx": "^2.0.0",
@ -115,8 +116,8 @@
"tailwind-scrollbar": "^3.0.5",
"tailwindcss": "^3.3.6",
"typescript": "^5.3.3",
"vite": "^5.0.7",
"vite-plugin-top-level-await": "^1.3.1",
"vite": "^5.0.8",
"vite-plugin-top-level-await": "^1.4.1",
"vite-tsconfig-paths": "^4.2.2"
}
}

File diff suppressed because it is too large Load Diff

25
scripts/rename.js Normal file
View File

@ -0,0 +1,25 @@
const fs = require('fs')
let extension = ''
if (process.platform === 'win32') {
extension = '.exe'
}
async function main() {
const host = Bun.spawn(["rustc", '-vV']);
const stdoutStr = await new Response(host.stdout).text();
const targetTriple = /host: (\S+)/g.exec(stdoutStr)[1]
if (!targetTriple) {
console.error('Failed to determine platform target triple')
}
fs.renameSync(
`src-tauri/bins/depot${extension}`,
`src-tauri/bins/depot-${targetTriple}${extension}`,
)
}
main().catch((e) => {
throw e
})

View File

@ -1,3 +1,6 @@
# Generated by Cargo
# will have compiled files and executables
/target/
/bin/depot-*
/bin/depot

7
src-tauri/Cargo.lock generated
View File

@ -2188,6 +2188,12 @@ dependencies = [
"pin-project-lite",
]
[[package]]
name = "http-range"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "21dec9db110f5f872ed9699c3ecf50cf16f423502706ba5c72462e28d3157573"
[[package]]
name = "httparse"
version = "1.8.0"
@ -4962,6 +4968,7 @@ dependencies = [
"gtk",
"heck",
"http",
"http-range",
"jni",
"libc",
"log",

View File

@ -17,6 +17,7 @@ serde = { version = "1.0", features = ["derive"] }
tauri = { version = "2.0.0-alpha", features = [
"macos-private-api",
"native-tls-vendored",
"protocol-asset",
] }
tauri-plugin-cli = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v2" }
tauri-plugin-clipboard-manager = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v2" }

0
src-tauri/bin/.keep Normal file
View File

View File

@ -0,0 +1,241 @@
# Nostr-rs-relay configuration
[info]
# The advertised URL for the Nostr websocket.
relay_url = "<url>"
# Relay information for clients. Put your unique server name here.
name = "depot"
# Description
description = "Nostr Relay inside Lume. Powered by nostr-rs-relay"
# Administrative contact pubkey (32-byte hex, not npub)
pubkey = "<pubkey>"
# Administrative contact URI
#contact = "mailto:contact@example.com"
# Favicon location. Relative to the current directory. Assumes an
# ICO format.
#favicon = "favicon.ico"
# URL of Relay's icon.
#relay_icon = "https://example.test/img.png"
[diagnostics]
# Enable tokio tracing (for use with tokio-console)
#tracing = false
[database]
# Database engine (sqlite/postgres). Defaults to sqlite.
# Support for postgres is currently experimental.
engine = "sqlite"
# Directory for SQLite files. Defaults to the current directory. Can
# also be specified (and overriden) with the "--db dirname" command
# line option.
data_directory = "."
# Use an in-memory database instead of 'nostr.db'.
# Requires sqlite engine.
# Caution; this will not survive a process restart!
#in_memory = false
# Database connection pool settings for subscribers:
# Minimum number of SQLite reader connections
#min_conn = 0
# Maximum number of SQLite reader connections. Recommend setting this
# to approx the number of cores.
max_conn = 8
# Database connection string. Required for postgres; not used for
# sqlite.
#connection = "postgresql://postgres:nostr@localhost:7500/nostr"
# Optional database connection string for writing. Use this for
# postgres clusters where you want to separate reads and writes to
# different nodes. Ignore for single-database instances.
#connection_write = "postgresql://postgres:nostr@localhost:7500/nostr"
[logging]
# Directory to store log files. Log files roll over daily.
#folder_path = "./log"
#file_prefix = "nostr-relay"
[grpc]
# gRPC interfaces for externalized decisions and other extensions to
# functionality.
#
# Events can be authorized through an external service, by providing
# the URL below. In the event the server is not accessible, events
# will be permitted. The protobuf3 schema used is available in
# `proto/nauthz.proto`.
# event_admission_server = "http://[::1]:50051"
# If the event admission server denies writes
# in any case (excluding spam filtering).
# This is reflected in the relay information document.
# restricts_write = true
[network]
# Bind to this network address
address = "0.0.0.0"
# Listen on this port
port = 6090
# If present, read this HTTP header for logging client IP addresses.
# Examples for common proxies, cloudflare:
#remote_ip_header = "x-forwarded-for"
#remote_ip_header = "cf-connecting-ip"
# Websocket ping interval in seconds, defaults to 5 minutes
#ping_interval = 300
[options]
# Reject events that have timestamps greater than this many seconds in
# the future. Recommended to reject anything greater than 30 minutes
# from the current time, but the default is to allow any date.
reject_future_seconds = 1800
[limits]
# Limit events created per second, averaged over one minute. Must be
# an integer. If not set (or set to 0), there is no limit. Note:
# this is for the server as a whole, not per-connection.
#
# Limiting event creation is highly recommended if your relay is
# public!
#
messages_per_sec = 10
# Limit client subscriptions created, averaged over one minute. Must
# be an integer. If not set (or set to 0), defaults to unlimited.
# Strongly recommended to set this to a low value such as 10 to ensure
# fair service.
subscriptions_per_min = 10
# UNIMPLEMENTED...
# Limit how many concurrent database connections a client can have.
# This prevents a single client from starting too many expensive
# database queries. Must be an integer. If not set (or set to 0),
# defaults to unlimited (subject to subscription limits).
#db_conns_per_client = 0
# Limit blocking threads used for database connections. Defaults to 16.
#max_blocking_threads = 16
# Limit the maximum size of an EVENT message. Defaults to 128 KB.
# Set to 0 for unlimited.
#max_event_bytes = 131072
# Maximum WebSocket message in bytes. Defaults to 128 KB.
#max_ws_message_bytes = 131072
# Maximum WebSocket frame size in bytes. Defaults to 128 KB.
#max_ws_frame_bytes = 131072
# Broadcast buffer size, in number of events. This prevents slow
# readers from consuming memory.
#broadcast_buffer = 16384
# Event persistence buffer size, in number of events. This provides
# backpressure to senders if writes are slow.
#event_persist_buffer = 4096
# Event kind blacklist. Events with these kinds will be discarded.
#event_kind_blacklist = [
# 70202,
#]
# Event kind allowlist. Events other than these kinds will be discarded.
#event_kind_allowlist = [
# 0, 1, 2, 3, 7, 40, 41, 42, 43, 44, 30023,
#]
# Rejects imprecise requests (kind only and author only etc)
# This is a temperary measure to improve the adoption of outbox model
# Its recommended to have this enabled
limit_scrapers = false
[authorization]
# Pubkey addresses in this array are whitelisted for event publishing.
# Only valid events by these authors will be accepted, if the variable
# is set.
pubkey_whitelist = []
# Enable NIP-42 authentication
nip42_auth = true
# Send DMs (kind 4 and 44) and gift wraps (kind 1059) only to their authenticated recipients
nip42_dms = true
[verified_users]
# NIP-05 verification of users. Can be "enabled" to require NIP-05
# metadata for event authors, "passive" to perform validation but
# never block publishing, or "disabled" to do nothing.
mode = "passive"
# Domain names that will be prevented from publishing events.
#domain_blacklist = ["wellorder.net"]
# Domain names that are allowed to publish events. If defined, only
# events NIP-05 verified authors at these domains are persisted.
#domain_whitelist = ["example.com"]
# Consider an pubkey "verified" if we have a successful validation
# from the NIP-05 domain within this amount of time. Note, if the
# domain provides a successful response that omits the account,
# verification is immediately revoked.
verify_expiration = "1 week"
# How long to wait between verification attempts for a specific author.
#verify_update_frequency = "24 hours"
# How many consecutive failed checks before we give up on verifying
# this author.
max_consecutive_failures = 3
[pay_to_relay]
# Enable pay to relay
#enabled = false
# The cost to be admitted to relay
#admission_cost = 4200
# The cost in sats per post
#cost_per_event = 0
# Url of lnbits api
#node_url = "<node url>"
# LNBits api secret
#api_secret = "<ln bits api>"
# Nostr direct message on signup
#direct_message=false
# Terms of service
#terms_message = """
#This service (and supporting services) are provided "as is", without warranty of any kind, express or implied.
#
#By using this service, you agree:
#* Not to engage in spam or abuse the relay service
#* Not to disseminate illegal content
#* That requests to delete content cannot be guaranteed
#* To use the service in compliance with all applicable laws
#* To grant necessary rights to your content for unlimited time
#* To be of legal age and have capacity to use this service
#* That the service may be terminated at any time without notice
#* That the content you publish may be removed at any time without notice
#* To have your IP address collected to detect abuse or misuse
#* To cooperate with the relay to combat abuse or misuse
#* You may be exposed to content that you might find triggering or distasteful
#* The relay operator is not liable for content produced by users of the relay
#"""
# Whether or not new sign ups should be allowed
#sign_ups = false
# optional if `direct_message=false`
#secret_key = "<nostr nsec>"

View File

@ -23,7 +23,8 @@
"$HOME/*",
"$PICTURE/*",
"$PUBLIC/*",
"$VIDEO/*"
"$VIDEO/*",
"$RESOURCE/*"
]
},
"http": {
@ -33,7 +34,10 @@
]
},
"shell": {
"open": true
"open": true,
"scope": [
{ "name": "bin/depot", "sidecar": true, "args": true }
]
},
"updater": {
"endpoints": [
@ -49,8 +53,8 @@
"deb": {
"depends": []
},
"externalBin": [],
"resources": [],
"externalBin": ["bin/depot"],
"resources": ["resources/config.toml"],
"icon": [
"icons/32x32.png",
"icons/128x128.png",
@ -88,6 +92,28 @@
"timestampUrl": ""
}
},
"security": {
"assetProtocol": {
"enable": true,
"scope": [
"$APPDATA/*",
"$DATA/*",
"$LOCALDATA/*",
"$DESKTOP/*",
"$DOCUMENT/*",
"$DOWNLOAD/*",
"$HOME/*",
"$PICTURE/*",
"$PUBLIC/*",
"$VIDEO/*",
"$APPCONFIG/*",
"$RESOURCE/*"
]
},
"dangerousDisableAssetCspModification": false,
"dangerousRemoteDomainIpcAccess": [],
"freezePrototype": false
},
"macOSPrivateApi": true
}
}

View File

@ -81,6 +81,13 @@ export default function App() {
return { Component: RelayScreen };
},
},
{
path: 'depot',
async lazy() {
const { DepotScreen } = await import('@app/depot');
return { Component: DepotScreen };
},
},
{
path: 'new',
element: <ComposerLayout />,

29
src/app/depot/index.tsx Normal file
View File

@ -0,0 +1,29 @@
import { configDir, resolveResource } from '@tauri-apps/api/path';
import { Command } from '@tauri-apps/plugin-shell';
export function DepotScreen() {
const launch = async () => {
const configPath = await resolveResource('resources/config.toml');
const dataPath = await configDir();
const command = Command.sidecar('bin/depot', ['-c', configPath, '-d', dataPath]);
const process = await command.spawn();
process.pid;
};
return (
<div className="flex flex-col items-center justify-center">
<div className="flex flex-col items-center gap-4 py-10">
<h1 className="text-center text-lg font-semibold">Depot</h1>
<button
type="button"
onClick={() => launch()}
className="h-9 w-max rounded-lg bg-blue-500 px-2 text-white"
>
Launch
</button>
</div>
</div>
);
}

View File

@ -78,6 +78,27 @@ export function Navigation() {
</>
)}
</NavLink>
<NavLink
to="/depot"
preventScrollReset={true}
className="inline-flex flex-col items-center justify-center"
>
{({ isActive }) => (
<>
<div
className={twMerge(
'inline-flex aspect-square h-auto w-full items-center justify-center rounded-lg',
isActive
? 'bg-black/10 text-black dark:bg-white/10 dark:text-white'
: 'text-black/50 dark:text-neutral-400'
)}
>
<RelayIcon className="h-6 w-6" />
</div>
<div className="text-sm font-medium text-black dark:text-white">Depot</div>
</>
)}
</NavLink>
</div>
<div className="flex shrink-0 flex-col gap-3 p-1">
<Link