|
@@ -147,86 +147,136 @@
|
|
|
path (util/node-path.join path "package.json")]
|
|
|
(fs/write-file! repo "" path (js/JSON.stringify data nil 2) {:skip-compare? true}))))
|
|
|
|
|
|
+(defn ^:private write_rootdir_file
|
|
|
+ [file content sub-root root-dir]
|
|
|
+ (p/let [repo ""
|
|
|
+ path (util/node-path.join root-dir sub-root)
|
|
|
+ exist? (fs/file-exists? path "")
|
|
|
+ _ (when-not exist? (fs/mkdir-recur! path))
|
|
|
+ user-path (util/node-path.join path file)
|
|
|
+ sub-dir? (string/starts-with? user-path path)
|
|
|
+ _ (when-not sub-dir?
|
|
|
+ (log/info :debug user-path)
|
|
|
+ (throw "write file denied"))
|
|
|
+ user-path-root (util/node-path.dirname user-path)
|
|
|
+ exist? (fs/file-exists? user-path-root "")
|
|
|
+ _ (when-not exist? (fs/mkdir-recur! user-path-root))
|
|
|
+ _ (fs/write-file! repo "" user-path content {:skip-compare? true})]
|
|
|
+ user-path))
|
|
|
+
|
|
|
(defn ^:private write_dotdir_file
|
|
|
[file content sub-root]
|
|
|
- (p/let [repo ""
|
|
|
- path (plugin-handler/get-ls-dotdir-root)
|
|
|
- path (util/node-path.join path sub-root)
|
|
|
- exist? (fs/file-exists? path "")
|
|
|
- _ (when-not exist? (fs/mkdir-recur! path))
|
|
|
+ (some-> (plugin-handler/get-ls-dotdir-root)
|
|
|
+ (p/then #(write_rootdir_file file content sub-root %))))
|
|
|
+
|
|
|
+(defn ^:private write_assetsdir_file
|
|
|
+ [file content sub-root]
|
|
|
+ (if-let [assets-dir (config/get-current-repo-assets-root)]
|
|
|
+ (write_rootdir_file file content sub-root assets-dir)
|
|
|
+ false))
|
|
|
+
|
|
|
+(defn ^:private read_rootdir_file
|
|
|
+ [file sub-root root-dir]
|
|
|
+ (p/let [path (util/node-path.join root-dir sub-root)
|
|
|
user-path (util/node-path.join path file)
|
|
|
- sub-dir? (string/starts-with? user-path path)
|
|
|
- _ (when-not sub-dir?
|
|
|
- (log/info :debug user-path)
|
|
|
- (throw "write file denied"))
|
|
|
- user-path-root (util/node-path.dirname user-path)
|
|
|
- exist? (fs/file-exists? user-path-root "")
|
|
|
- _ (when-not exist? (fs/mkdir-recur! user-path-root))
|
|
|
- _ (fs/write-file! repo "" user-path content {:skip-compare? true})]
|
|
|
- user-path))
|
|
|
+ sub-dir? (string/starts-with? user-path path)
|
|
|
+ _ (when-not sub-dir? (log/info :debug user-path) (throw "read file denied"))
|
|
|
+ exist? (fs/file-exists? "" user-path)
|
|
|
+ _ (when-not exist? (log/info :debug user-path) (throw "file not existed"))
|
|
|
+ content (fs/read-file "" user-path)]
|
|
|
+ content))
|
|
|
|
|
|
(defn ^:private read_dotdir_file
|
|
|
[file sub-root]
|
|
|
- (p/let [path (plugin-handler/get-ls-dotdir-root)
|
|
|
- path (util/node-path.join path sub-root)
|
|
|
+ (some-> (plugin-handler/get-ls-dotdir-root)
|
|
|
+ (p/then #(read_rootdir_file file sub-root %))))
|
|
|
+
|
|
|
+(defn ^:private read_assetsdir_file
|
|
|
+ [file sub-root]
|
|
|
+ (when-let [root-dir (config/get-current-repo-assets-root)]
|
|
|
+ (read_rootdir_file file sub-root root-dir)))
|
|
|
+
|
|
|
+(defn ^:private unlink_rootdir_file!
|
|
|
+ [file sub-root root-dir]
|
|
|
+ (p/let [repo ""
|
|
|
+ path (util/node-path.join root-dir sub-root)
|
|
|
user-path (util/node-path.join path file)
|
|
|
- sub-dir? (string/starts-with? user-path path)
|
|
|
- _ (when-not sub-dir? (log/info :debug user-path) (throw "read file denied"))
|
|
|
- exist? (fs/file-exists? "" user-path)
|
|
|
- _ (when-not exist? (log/info :debug user-path) (throw "file not existed"))
|
|
|
- content (fs/read-file "" user-path)]
|
|
|
- content))
|
|
|
+ sub-dir? (string/starts-with? user-path path)
|
|
|
+ _ (when-not sub-dir? (log/info :debug user-path) (throw "access file denied"))
|
|
|
+ exist? (fs/file-exists? "" user-path)
|
|
|
+ _ (when-not exist? (log/info :debug user-path) (throw "file not existed"))
|
|
|
+ _ (fs/unlink! repo user-path {})]))
|
|
|
|
|
|
(defn ^:private unlink_dotdir_file!
|
|
|
[file sub-root]
|
|
|
- (p/let [repo ""
|
|
|
- path (plugin-handler/get-ls-dotdir-root)
|
|
|
- path (util/node-path.join path sub-root)
|
|
|
- user-path (util/node-path.join path file)
|
|
|
- sub-dir? (string/starts-with? user-path path)
|
|
|
- _ (when-not sub-dir? (log/info :debug user-path) (throw "access file denied"))
|
|
|
- exist? (fs/file-exists? "" user-path)
|
|
|
- _ (when-not exist? (log/info :debug user-path) (throw "file not existed"))
|
|
|
- _ (fs/unlink! repo user-path {})]))
|
|
|
+ (some-> (plugin-handler/get-ls-dotdir-root)
|
|
|
+ (p/then #(unlink_rootdir_file! file sub-root %))))
|
|
|
+
|
|
|
+(defn ^:private unlink_assetsdir_file!
|
|
|
+ [file sub-root]
|
|
|
+ (when-let [root-dir (config/get-current-repo-assets-root)]
|
|
|
+ (unlink_rootdir_file! file sub-root root-dir)))
|
|
|
|
|
|
(def ^:export write_user_tmp_file
|
|
|
(fn [file content]
|
|
|
(write_dotdir_file file content "tmp")))
|
|
|
|
|
|
(def ^:export write_plugin_storage_file
|
|
|
- (fn [plugin-id file content]
|
|
|
- (write_dotdir_file
|
|
|
- file content
|
|
|
- (let [plugin-id (util/node-path.basename plugin-id)]
|
|
|
- (util/node-path.join "storages" plugin-id)))))
|
|
|
+ (fn [plugin-id file content assets?]
|
|
|
+ (let [plugin-id (util/node-path.basename plugin-id)
|
|
|
+ sub-root (util/node-path.join "storages" plugin-id)]
|
|
|
+ (if (true? assets?)
|
|
|
+ (write_assetsdir_file file content sub-root)
|
|
|
+ (write_dotdir_file file content sub-root)))))
|
|
|
|
|
|
(def ^:export read_plugin_storage_file
|
|
|
- (fn [plugin-id file]
|
|
|
- (let [plugin-id (util/node-path.basename plugin-id)]
|
|
|
- (read_dotdir_file
|
|
|
- file (util/node-path.join "storages" plugin-id)))))
|
|
|
+ (fn [plugin-id file assets?]
|
|
|
+ (let [plugin-id (util/node-path.basename plugin-id)
|
|
|
+ sub-root (util/node-path.join "storages" plugin-id)]
|
|
|
+ (if (true? assets?)
|
|
|
+ (read_assetsdir_file file sub-root)
|
|
|
+ (read_dotdir_file file sub-root)))))
|
|
|
|
|
|
(def ^:export unlink_plugin_storage_file
|
|
|
- (fn [plugin-id file]
|
|
|
- (let [plugin-id (util/node-path.basename plugin-id)]
|
|
|
- (unlink_dotdir_file!
|
|
|
- file (util/node-path.join "storages" plugin-id)))))
|
|
|
+ (fn [plugin-id file assets?]
|
|
|
+ (let [plugin-id (util/node-path.basename plugin-id)
|
|
|
+ sub-root (util/node-path.join "storages" plugin-id)]
|
|
|
+ (if (true? assets?)
|
|
|
+ (unlink_assetsdir_file! file sub-root)
|
|
|
+ (unlink_dotdir_file! file sub-root)))))
|
|
|
|
|
|
(def ^:export exist_plugin_storage_file
|
|
|
- (fn [plugin-id file]
|
|
|
- (p/let [root (plugin-handler/get-ls-dotdir-root)
|
|
|
+ (fn [plugin-id file assets?]
|
|
|
+ (p/let [root (if (true? assets?)
|
|
|
+ (config/get-current-repo-assets-root)
|
|
|
+ (plugin-handler/get-ls-dotdir-root))
|
|
|
plugin-id (util/node-path.basename plugin-id)
|
|
|
- exist? (fs/file-exists?
|
|
|
- (util/node-path.join root "storages" plugin-id)
|
|
|
- file)]
|
|
|
+ exist? (fs/file-exists?
|
|
|
+ (util/node-path.join root "storages" plugin-id)
|
|
|
+ file)]
|
|
|
exist?)))
|
|
|
|
|
|
(def ^:export clear_plugin_storage_files
|
|
|
- (fn [plugin-id]
|
|
|
- (p/let [root (plugin-handler/get-ls-dotdir-root)
|
|
|
+ (fn [plugin-id assets?]
|
|
|
+ (p/let [root (if (true? assets?)
|
|
|
+ (config/get-current-repo-assets-root)
|
|
|
+ (plugin-handler/get-ls-dotdir-root))
|
|
|
plugin-id (util/node-path.basename plugin-id)]
|
|
|
(fs/rmdir! (util/node-path.join root "storages" plugin-id)))))
|
|
|
|
|
|
+(def ^:export list_plugin_storage_files
|
|
|
+ (fn [plugin-id assets?]
|
|
|
+ (p/let [root (if (true? assets?)
|
|
|
+ (config/get-current-repo-assets-root)
|
|
|
+ (plugin-handler/get-ls-dotdir-root))
|
|
|
+ plugin-id (util/node-path.basename plugin-id)
|
|
|
+ files-path (util/node-path.join root "storages" plugin-id)
|
|
|
+ ^js files (ipc/ipc :listdir files-path)]
|
|
|
+ (when (js-iterable? files)
|
|
|
+ (bean/->js
|
|
|
+ (map #(some-> (string/replace-first % files-path "")
|
|
|
+ (string/replace #"^/+" "")) files))))))
|
|
|
+
|
|
|
(def ^:export load_user_preferences
|
|
|
(fn []
|
|
|
(p/let [repo ""
|