about summary refs log tree commit diff
diff options
context:
space:
mode:
authorAlexander_Kabui2024-08-07 17:51:47 +0300
committerMunyoki Kilyungi2024-08-09 11:55:16 +0300
commit44615cd691f854a882ba8fc4cff216718793d56d (patch)
treea76f609f0f02f3afd2abe1f37c4024cfb071ee15
parent8052d004e4065e39d2ddd4a6e9dcc03f2fbee5bb (diff)
downloadgn-guile-44615cd691f854a882ba8fc4cff216718793d56d.tar.gz
Replace string-append with format.
-rw-r--r--web/view/markdown.scm16
-rwxr-xr-xweb/webserver.scm13
2 files changed, 14 insertions, 15 deletions
diff --git a/web/view/markdown.scm b/web/view/markdown.scm
index 5f3474c..fd8838f 100644
--- a/web/view/markdown.scm
+++ b/web/view/markdown.scm
@@ -20,8 +20,8 @@
             markdown-github->sxml
             fetch-file
             fetch-raw-file
-            commit-file
-            is-repo?))
+            commit-file))
+
 
 (define (markdown-file->sxml fn)
   "Parse a local file"
@@ -57,14 +57,14 @@
           (br))))
 
 (define (fetch-file repo query-path)
-  (let* ( (abs-path (string-append repo "/" query-path)))
+  (let* ( (abs-path (format #f "~a/~a" repo query-path)))
     (if (file-exists? abs-path)  (let* ((full-path (canonicalize-path abs-path))
                                         (content (call-with-input-file full-path get-string-all))
                                         (commit-sha (get-latest-commit-sha1 repo)))
                                    `(("file_path" . ,query-path)
                                      ("content" . ,content)
                                      ("hash" . ,commit-sha))
-                                   ) (throw 'file-error  (string-append "the file path " abs-path " does not exists")))))
+                                   ) (throw 'file-error  (format #f "~a does not exists" abs-path)))))
 
 (define (git-invoke repo-path . args)
   (apply system* "git" "-C" repo-path args))
@@ -84,9 +84,9 @@
     (throw 'system-error (format #f "Commits do no match.Please pull in latest  changes for current * ~a * and prev * ~a * "
                                  (get-latest-commit-sha1 repo) prev-commit)))
   (if (git-repository? repo)
-      (match (file-exists? (string-append repo "/" file-path))
+      (match (file-exists? (format #f "~a/~a" repo file-path))
         (#t
-         (with-output-to-file (string-append repo "/" file-path)
+         (with-output-to-file (format #f "~a/~a" repo file-path)
            (lambda ()
              (display content)))
          (let* ((git-add-file (git-invoke repo "add" file-path))
@@ -100,5 +100,5 @@
                `(("status" . "201") ("message" . "committed file successfully") ("content" . ,content) ("commit_sha" . ,git-commit-sha) ("commit_message" . ,commit-message) )
                `(("status" . "200") ("message" . "Nothing to commit, working tree clean") ("commit_sha" . ,git-commit-sha)))))
         (#f
-         (throw 'system-error (string-append file-path  " File does not exist Error"))))
-      (throw 'system-error (string-append repo " Is not a git repo."))))
+         (throw 'system-error (format #f "~a File does not exist error" file-path))))
+      (throw 'system-error (format #f  "~a is no a git repo" repo))))
diff --git a/web/webserver.scm b/web/webserver.scm
index 2dab5b1..3cfcf50 100755
--- a/web/webserver.scm
+++ b/web/webserver.scm
@@ -137,11 +137,6 @@ otherwise search for set/group data"
    (lambda (port)
      (scm->json json port))))
 
-(define (decode-query query)
-  (if (not query)
-      '()
-      (map decode-query-component (string-split query #\&))))
-
 (define (decode-request-json body)
   (if (not body)
       '()
@@ -157,10 +152,14 @@ otherwise search for set/group data"
 (define (edit-file-handler  repo request)
   (catch 'file-error
     (lambda ()
-      (let* ((params (decode-query (uri-query (request-uri request)))) (query-path (assoc-ref params 'file_path)))
+      (let* ((query (uri-query (request-uri request)))
+             (params (if (not query)
+                         '()
+                         (map decode-query-component (string-split query #\&))))
+             (query-path (assoc-ref params 'file_path)))
         (if query-path
             (build-json-response 400 (fetch-file repo query-path))
-            (throw 'file-error (string-append "Please provide a valid file path in the query")))))
+            (throw 'file-error "Please provide a valid file path in the query"))))
     (lambda (key . args)
       (let ((msg (car args))) (build-json-response 400 `(("error" . ,key) ("msg" . ,msg)))))))