Skip to content

Commit

Permalink
feat: codeクエリパラメータをつけてアクセスするとテキストを埋め込んだ状態で画面を表示する #181 (#192)
Browse files Browse the repository at this point in the history
* 依存ライブラリのバージョンを上げた

* code クエリパラメータでシェルを渡せるようにした #181

* ベースURLを定数化、クエリパラメータをつけたリンクを表示するように変更

* デコード処理を修正
  • Loading branch information
jiro4989 authored Nov 25, 2020
1 parent 11de0e4 commit 24e1c9f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
24 changes: 20 additions & 4 deletions websh_front/src/index.nim
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from strutils import split
from strformat import `&`
from unicode import isAlpha, toRunes, runeAt, `==`, `$`
from uri import encodeUrl
from uri import encodeUrl, decodeUrl
from sequtils import mapIt, toSeq, filterIt, delete
import json except `%*`

Expand Down Expand Up @@ -32,10 +32,12 @@ let

when defined local:
# ローカル開発用
const apiUrl = "http://localhost/api/shellgei"
const baseUrl = "http://localhost"
const apiUrl = &"{baseUrl}/api/shellgei"
else:
# 本番用
const apiUrl = "https://websh.jiro4989.com/api/shellgei"
const baseUrl = "https://websh.jiro4989.com"
const apiUrl = &"{baseUrl}/api/shellgei"

proc newMediaObj(): MediaObj = MediaObj(name: cstring"", data: cstring"")

Expand All @@ -58,6 +60,16 @@ if localstorage.hasItem("history"):
let hist = localstorage.getItem("history").`$`.parseJson.to(seq[string])
shellHistory.add(hist)

proc getCode(q: string): cstring =
let s = q[1..^1]
let kv = s.split("=")
let v = kv[1]
result = decodeUrl(v)

let query = window.location[].search.`$`
if 1 < query.len:
inputShell.add(query.getCode)

proc respCb(httpStatus: int, response: cstring) =
let resp = fromJson[ResponseResult](response)
outputStatus = resp.status
Expand Down Expand Up @@ -181,7 +193,8 @@ proc createDom(): VNode =
setFocus = true,
onkeydown = inputTextareaOnkeydown,
onkeyup = inputTextareaOnkeyup,
)
):
text inputShell
for ii in 0..<inputImages.len:
tdiv(class="file has-name is-primary"):
label(class="file-label"):
Expand Down Expand Up @@ -211,6 +224,9 @@ proc createDom(): VNode =
for elem in @[cstring"シェル芸", cstring"shellgei", cstring"ゆるシェル", cstring"危険シェル芸", ]:
option(value = $elem):
text $elem
tdiv:
a(href = &"{baseUrl}?code={encodeUrl($inputShell, false)}"):
text &"{baseUrl}?code={encodeUrl($inputShell, false)}"
article(class = "tile is-child notification"):
p(class = "title"):
text "history"
Expand Down
4 changes: 2 additions & 2 deletions websh_front/websh_front.nimble
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ backend = "js"

# Dependencies

requires "nim >= 1.0.2"
requires "karax#c00d7dc34031aa9a74b54a632b21caaec03d3fea"
requires "nim >= 1.4.0"
requires "karax >= 1.1.3"
2 changes: 1 addition & 1 deletion websh_server/websh_server.nimble
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ binDir = "bin"

# Dependencies

requires "nim >= 1.2.0"
requires "nim >= 1.4.0"
requires "jester#7e8df6543a57c3ef31d1e5ae33f88a707486ec11"
requires "uuids >= 0.1.10"

0 comments on commit 24e1c9f

Please sign in to comment.