Netnr.FileServer
基于 .NET Core 的簡單檔案服務器,資料庫為SQLite
原始碼
- https://github.com/netnr/np
- https://gitee.com/netnr/np
配置
appsettings.json 為組態檔
正式環境在創建 App 之后需設定 IsDev:false,設定直接生效不用重啟服務
檔案資料庫 和 上傳目錄 賦予讀寫權限
運行
在根目錄運行:dotnet Netnr.FileServer.dll "http://*:42"
Linux后臺運行:nohup dotnet Netnr.FileServer.dll "http://*:42" &
Windows可直接雙擊Netnr.FileServer.exe,或命令運行Netnr.FileServer.exe "http://*:42" 不能關閉
或者說掛載IIS
訪問
服務運行后,訪問 {Host}/swagger,可以直接使用所有的介面
授權
首先創建 App 得到 AppId 、AppKey,然后根據 AppId、AppKey 請求得到 Token,
Token 可根據配置設定有效期,默認30分鐘有效,快取20分鐘(即20分鐘內請求Token回傳結果相同)
介面
/api/createapp創建App,非正式環境使用/api/getapplist獲取App串列,非正式環境使用/api/resetall清空資料庫和上傳目錄,非正式環境使用- 在正式環境下一定要修改配置
IsDev:false, 關閉以上介面
/api/gettoken根據AppId、AppKey請求Token/api/upload上傳檔案/api/copy復制檔案/api/cover上傳檔案覆寫/api/delete洗掉檔案
上傳
默認上傳到目錄 wwwroot/static/ , /static/可根據組態檔配置
分離
為了更好的維護或資料的安全,需要分離檔案資料庫和上傳的靜態目錄,
可以用 軟鏈接 的方式來做,非 Windows的快捷方式
// Windows 軟鏈接
// 命令格式
mklink /d 軟鏈接目錄 物理目錄
// 示例 在當前創建 static 目錄 指向 D盤的 static 目錄
mklink /d static D:\static
# Linux 軟鏈接
ln -s 源檔案 軟鏈接檔案 # 命令格式
# 示例 gs 指向 /netnr/site/static 目錄
ln -s /netnr/site/static /netnr/site/www/wwwroot/gs
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/84818.html
標籤:.NET Core
上一篇:個站開源啦
