Save code only by Save button. Save always to new location

This commit is contained in:
Nikolay Puzanov 2022-12-09 09:07:13 +03:00
parent d04282e1c7
commit 1bc6ec544d
2 changed files with 15 additions and 42 deletions

View File

@ -132,7 +132,6 @@
<div id="buttons"> <div id="buttons">
<button onclick="show_help()"><span class="text">?</span></button> <button onclick="show_help()"><span class="text">?</span></button>
<button onclick="save_code('%SAVECODEURI%')"><span class="text">Save (ctrl-s)</span></button> <button onclick="save_code('%SAVECODEURI%')"><span class="text">Save (ctrl-s)</span></button>
<button onclick="save_code('%SAVEASURI%')"><span class="text">Save as new</span></button>
Sim: Sim:
<button onclick="send_to_sim('%IVERILOGPOSTURI%')"><span class="text">Icarus</span></button> <button onclick="send_to_sim('%IVERILOGPOSTURI%')"><span class="text">Icarus</span></button>
<button onclick="send_to_sim('%VERILATORPOSTURI%')"><span class="text">Verilator</span></button> <button onclick="send_to_sim('%VERILATORPOSTURI%')"><span class="text">Verilator</span></button>

View File

@ -38,7 +38,6 @@
(define URI-IVERILOG "iverilog") (define URI-IVERILOG "iverilog")
(define URI-VERILATOR "verilator") (define URI-VERILATOR "verilator")
(define URI-SAVE-CODE "save") (define URI-SAVE-CODE "save")
(define URI-SAVEAS-CODE "saveas")
(define LOG-DBG 3) (define LOG-DBG 3)
(define LOG-VERBOSE 2) (define LOG-VERBOSE 2)
@ -776,14 +775,12 @@
(iverilog-path (append root-path `(,URI-IVERILOG))) (iverilog-path (append root-path `(,URI-IVERILOG)))
(verilator-path (append root-path `(,URI-VERILATOR))) (verilator-path (append root-path `(,URI-VERILATOR)))
(savecode-path (append root-path `(,URI-SAVE-CODE))) (savecode-path (append root-path `(,URI-SAVE-CODE)))
(saveas-path (append root-path `(,URI-SAVEAS-CODE)))
(index-html (index-html
(read-template-text (read-template-text
index-file index-file
`(("IVERILOGPOSTURI" ,(encode-and-join-uri-path iverilog-path)) `(("IVERILOGPOSTURI" ,(encode-and-join-uri-path iverilog-path))
("VERILATORPOSTURI" ,(encode-and-join-uri-path verilator-path)) ("VERILATORPOSTURI" ,(encode-and-join-uri-path verilator-path))
("SAVECODEURI" ,(encode-and-join-uri-path savecode-path)) ("SAVECODEURI" ,(encode-and-join-uri-path savecode-path))
("SAVEASURI" ,(encode-and-join-uri-path saveas-path))
("HELPSTRING", ("HELPSTRING",
(string-concatenate (string-concatenate
(insert-between (insert-between
@ -812,15 +809,6 @@
(uri-path (uri-path
(request-uri request)))) (request-uri request))))
;; Snippet dir path relative to stor-base
(ref-stor-dir
(let ((ref (assoc 'referer (request-headers request))))
(and ref
(let ((p (get-storage-dir (cdr ref) root)))
(and (storage-dir-valid? p)
(storage-path-exists? (path+ stor-base p))
p)))))
;; Body of the POST request ;; Body of the POST request
(code (code
(if request-body (if request-body
@ -840,10 +828,6 @@
(logger LOG-VERBOSE "Request ~a:~a" (request-method request) path) (logger LOG-VERBOSE "Request ~a:~a" (request-method request) path)
(logger LOG-VERBOSE "Request query:~a" query) (logger LOG-VERBOSE "Request query:~a" query)
(logger LOG-DBG " stor:'~a' len:~a/~a"
ref-stor-dir
(request-content-length request)
(string-length code))
(cond (cond
;; ;;
@ -900,10 +884,6 @@
'verilator))) 'verilator)))
(logger LOG-DBG "Request ~a simulation" (symbol->string simulator)) (logger LOG-DBG "Request ~a simulation" (symbol->string simulator))
(when ref-stor-dir
(save-to-storage (path+ stor-base ref-stor-dir) code))
(let-values (let-values
(((log vcd) (((log vcd)
(exec-sim simulator (exec-sim simulator
@ -927,27 +907,21 @@
#:content-type 'text/plain))))) #:content-type 'text/plain)))))
;; Save snippet ;; Save snippet
((or (equal? path savecode-path) ((or (equal? path savecode-path))
(equal? path saveas-path)) (logger LOG-DBG "Request code saving")
(let ((saveas (equal? path saveas-path)))
(logger LOG-DBG "Request code saving~a"
(if saveas " as new snippet" ""))
(let ((stor-dir (let ((stor-dir
(if (or saveas
(not ref-stor-dir))
(basename (basename
(mkdtemp (mkdtemp
(path+ (path+
stor-base stor-base
(if USE-TIME-IN-SAVE-URL (if USE-TIME-IN-SAVE-URL
(format "~a-XXXXXX" (current-time)) (format "~a-XXXXXX" (current-time))
"XXXXXX")))) "XXXXXX"))))))
ref-stor-dir)))
(save-to-storage (path+ stor-base stor-dir) code) (save-to-storage (path+ stor-base stor-dir) code)
(make-response (make-response
(encode-and-join-uri-path (encode-and-join-uri-path
(append root-path `(,stor-dir))) (append root-path `(,stor-dir)))
#:content-type 'text/plain)))) #:content-type 'text/plain)))
;; Wrong POST request ;; Wrong POST request
(else (else