diff --git a/.gitignore b/.gitignore
index 3be6c8d..faeeac7 100644
--- a/.gitignore
+++ b/.gitignore
@@ -28,6 +28,7 @@ npminstall-debug.log
# local env files
.env
.env*.local
+.pwd
# vercel
.vercel
diff --git a/.env.example b/.pwd.example
similarity index 100%
rename from .env.example
rename to .pwd.example
diff --git a/README-zh_CN.md b/README-zh_CN.md
deleted file mode 100644
index 582552b..0000000
--- a/README-zh_CN.md
+++ /dev/null
@@ -1,201 +0,0 @@
-
-
-
-
-# Ferrum 文件管理器
-
-[![Author](https://img.shields.io/badge/Author-NriotHrreion-red.svg "Author")](https://github.com/NriotHrreion)
-[![LICENSE](https://img.shields.io/badge/license-MIT-green.svg "LICENSE")](./LICENSE)
-[![Stars](https://img.shields.io/github/stars/nocpiun/ferrum.svg?label=Stars)](https://github.com/nocpiun/ferrum/stargazers)
-[![test](https://img.shields.io/github/actions/workflow/status/nocpiun/ferrum/ci.yml)](https://github.com/nocpiun/ferrum/actions/workflows/ci.yml)
-[![Netlify Status](https://api.netlify.com/api/v1/badges/e6af7829-7b1c-47ed-bf14-deb2b2d9648a/deploy-status)](https://app.netlify.com/sites/resonant-kitsune-43a162/deploys)
-
-> Explore throughout your server
-
-[English](./README.md) | 中文
-
-
-
-## 简介
-
-Ferrum 文件管理器是一个基于Web的服务器文件管理器应用.
-
-因为此项目只被我一个人维护, 所以有很多问题和bug. 你可以为此项目题issue来告诉我或者开一个Pull Request来修复它.
-
-#### 为什么它的名字是ferrum?
-
-```
-File Explorer -> FE -> Fe (化学元素) -> Ferrum
-```
-
-#### 我可以看看它吗?
-
-Demo: https://ferrum-demo.nin.red (密码: `123456`)
-
-## 部署 & 使用
-
-首先, 你需要确保你的服务器(或电脑)已经安装了Nodejs.
-
-1. 下载与安装
-
-```bash
-git clone https://github.com/nocpiun/ferrum.git
-cd ferrum
-npm i
-```
-
-2. 运行
-
-```bash
-npm run start
-```
-
-如果你用的是Linux, 你需要在这个命令前面加上`sudo`.
-
-3. 进入 `http://localhost:3300`, 默认密码是`123456`.
-
-### 获取更新
-
-执行下面的命令, 然后再`npm run start`.
-
-```bash
-git fetch origin main:temp
-git merge temp
-npm i
-```
-
-如果在`npm i`的时候报错, 可以试试看:
-
-```bash
-npm i --legacy-peer-deps
-# or
-npm i --force
-```
-
-### 注意事项
-
-Ferrum 文件管理器需要`3300`与`3301`两个端口来启动. 如果它报错`address already in use :::xxxx`, 那么你就得检查一下是否你已经启动了Ferrum以及其它应用是否在占用这两个端口, 然后看看下面的步骤.
-
-**Windows**
-
-```bash
-netstat -aon | findstr [[此处写它返回的端口号]]
-taskkill /f /pid [[此处写上面命令返回的PID]]
-```
-
-**Linux & Mac OS**
-
-```bash
-lsof -i:[[此处写它返回的端口号]]
-kill -9 [[此处写上面命令返回的PID]]
-```
-
-如果你在Linux环境下遇到`ENOSPC: System limit for number of file watchers reached, watch 'xxx'`, 那么请尝试:
-
-```bash
-sudo sysctl fs.inotify.max_user_watches=582222 && sudo sysctl -p
-```
-
-## 插件
-
-#### 编写文件查看器插件
-
-如果你打算写一个查看器插件, 你首先需要创建一个`jsx`后缀的文件, 然后你需要为你的插件提供如下的信息. (下面是一个完整的示例).
-
-```jsx
-({
- name: "example-viewer",
- displayName: "Example Viewer",
- setup({ addViewer }) {
- addViewer({
- id: "example-viewer", // 插件ID
- pageTitle: "Example Viewer", // 查看器页面的标题
- route: "/example-viewer", // 查看器页面的路由
- formats: [], // 查看器支持的文件格式
- render: (dataUrl) => {dataUrl}
// 查看器页面的渲染器 (`dataUrl`是一个base64的data url)
- });
- }
-})
-```
-
-然后, 在设置中添加你的插件.
-
-#### 插件多语言
-
-如果你想让你的插件支持多个语言, 你只需要先创建一个存储文本的变量:
-
-```jsx
-const i18n = {
- "zh-CN": {
- "plugin.hello": "你好"
- },
- "en": {
- "plugin.hello": "Hello"
- }
-};
-```
-
-然后, 在你的插件信息列表里面添加这个变量:
-
-```jsx
-({
- // ...
- setup(apis) {
- // ...
- },
- i18n, // <== 这里
- // ...
-})
-```
-
-If you would like to use one of the texts in the i18n list, you just need to write down the key of the text and add a `$` before it. For example: `$plugin.hello`.
-接着在你想使用它的时候, 写下文本对应的key, 再在前面加一个`$`, 比如: `$plugin.hello`.
-
-```jsx
-({
- // ...
- setup({ addViewer }) {
- addViewer({
- // ...
- pageTitle: "$plugin.hello", // <== 就像这样
- // ...
- });
- },
- i18n,
- // ...
-})
-```
-
-## 测试
-
-Ferrum使用Jest来测试代码.
-
-```bash
-npm run test
-```
-
-## 贡献
-
-欢迎为Ferrum 文件管理器做贡献. 如果你不知道怎么做, 请看: [Creating a Pull Request from a Fork](https://help.github.com/en/github/collaborating-with-issues-and-pull-requests/creating-a-pull-request-from-a-fork).
-
-我会在我有空的时候检查Pull Request, 但我不敢保证每个Pull Request都会立刻被我看见.
-
-## 运行脚本
-
-一些在`package.json`里的运行脚本.
-
-- **`start`** 在生产模式下启动App
-- **`dev`** 在开发模式下启动App
-- **`server`** 只启动后端服务器
-- **`client`** 只启动客户端
-- **`build`** 构建项目(不单独使用)
-- **`build:netlify`** 构建项目(Netlify部署专用)
-- **`test`** 运行测试代码
-
-## Note
-
-> **Fun Fact:** 此项目向[Takenote](https://github.com/taniarascia/takenote)学习了许多. Takenote也非常牛逼.
-
-## LICENSE
-
-[MIT](./LICENSE)
diff --git a/README.md b/README.md
index 08a5954..07f31a4 100644
--- a/README.md
+++ b/README.md
@@ -1,26 +1,24 @@
-
+
# Ferrum Explorer
[![Author](https://img.shields.io/badge/Author-NriotHrreion-red.svg "Author")](https://github.com/NriotHrreion)
[![LICENSE](https://img.shields.io/badge/license-MIT-green.svg "LICENSE")](./LICENSE)
[![Stars](https://img.shields.io/github/stars/nocpiun/ferrum.svg?label=Stars)](https://github.com/nocpiun/ferrum/stargazers)
-[![test](https://img.shields.io/github/actions/workflow/status/nocpiun/ferrum/ci.yml)](https://github.com/nocpiun/ferrum/actions/workflows/ci.yml)
+[![test](https://img.shields.io/github/actions/workflow/status/nocpiun/ferrum/lint.yml)](https://github.com/nocpiun/ferrum/actions/workflows/lint.yml)
[![Netlify Status](https://api.netlify.com/api/v1/badges/e6af7829-7b1c-47ed-bf14-deb2b2d9648a/deploy-status)](https://app.netlify.com/sites/resonant-kitsune-43a162/deploys)
> Explore throughout your server
-English | [中文](./README-zh_CN.md)
-
## Description
Ferrum Explorer is a web-based file explorer app for servers.
-Because it's only maintained by me, so it has many problems and bugs. You can create a issue or pull request to tell me or fix it.
+Because it's only maintained by me, so it might have some problems and bugs. You can raise an issue or create a pull request to tell me or fix it.
#### Why its name is Ferrum?
@@ -28,10 +26,6 @@ Because it's only maintained by me, so it has many problems and bugs. You can cr
File Explorer -> FE -> Fe (Chemical Element) -> Ferrum
```
-#### Can I have a look of it?
-
-Demo: https://ferrum-demo.nin.red (The password is `123456`)
-
## Deploy & Use
First, you need to make sure that your server (or computer) has installed Nodejs.
@@ -42,17 +36,24 @@ First, you need to make sure that your server (or computer) has installed Nodejs
git clone https://github.com/nocpiun/ferrum.git
cd ferrum
npm i
+npm run build
```
-2. Run the app
+2. Prepare the `.pwd` file
+
+Rename the `.pwd.example` to `.pwd` in the project root folder. And delete the comments in it. This file stores your access key to Ferrum. The default password is `123456`, and you can change your password in the settings.
+
+```txt
+PASSWORD=....
+```
+
+3. Run the app (Recommended to use Administrator privilege)
```bash
npm run start
```
-If you're using Linux, you need to add `sudo` before the command.
-
-3. Enter `http://localhost:3300`, the default password is `123456`.
+4. Enter `http://localhost:3300`.
### To get update
@@ -74,7 +75,7 @@ npm i --force
### Something to notice
-Ferrum Explorer requires ports `3300` `3301` to launch. If you see it reports `address already in use :::xxxx`, you should have a check to whether you've launched Ferrum Explorer and whether other apps are using the ports. And see the following steps.
+Ferrum Explorer requires ports `3300` to launch. If you see it reports `address already in use :::xxxx`, you should have a check to whether you've launched Ferrum Explorer and whether other apps are using the ports. And see the following steps.
**Windows**
@@ -90,91 +91,6 @@ lsof -i:[[here write the port it reported]]
kill -9 [[here write the PID the above command returned]]
```
-If it reports `ENOSPC: System limit for number of file watchers reached, watch 'xxx'` and you're using Linux, please do:
-
-```bash
-sudo sysctl fs.inotify.max_user_watches=582222 && sudo sysctl -p
-```
-
-## Plugin
-
-#### Write a Viewer Plugin
-
-Viewer is a page that is shown when the user opens a file. The viewer's page will be shown when the user opens the file format(s) the viewer's option has specified. For example, a video viewer, its page will be shown when the user open a `.mp4` file.
-
-You need to create a new `jsx` file. And a metadata list of the plugin is needed. (The following is a complete example).
-
-```jsx
-({
- name: "example-viewer",
- displayName: "Example Viewer",
- setup({ addViewer }) {
- addViewer({
- id: "example-viewer", // The ID of your viewer
- pageTitle: "Example Viewer", // This will be shown on the top of your viewer's page
- route: "/example-viewer", // The route of your viewer's page
- formats: [], // The formats that your viewer supports
- render: (dataUrl) => {dataUrl}
// The render of your viewer (`dataUrl` is a base64 data url)
- });
- }
-})
-```
-
-Then, add your plugin in settings.
-
-#### Plugin I18n
-
-If you want to make your plugin supports different languages, just create a variable that stores your texts:
-
-```jsx
-const i18n = {
- "zh-CN": {
- "plugin.hello": "你好"
- },
- "en": {
- "plugin.hello": "Hello"
- }
-};
-```
-
-Then, put this variable into your plugin metadata list:
-
-```jsx
-({
- // ...
- setup(apis) {
- // ...
- },
- i18n, // <== Here
- // ...
-})
-```
-
-If you would like to use one of the texts in the i18n list, you just need to write down the key of the text and add a `$` before it. For example: `$plugin.hello`.
-
-```jsx
-({
- // ...
- setup({ addViewer }) {
- addViewer({
- // ...
- pageTitle: "$plugin.hello", // <== Just like that
- // ...
- });
- },
- i18n,
- // ...
-})
-```
-
-## Testing
-
-Ferrum Explorer is using Jest to test code.
-
-```bash
-npm run test
-```
-
## Contributing
Contributions to Ferrum Explorer are welcomed. You can fork this project and start your contributing. If you don't know how to do, please follow the instruction [Creating a Pull Request from a Fork](https://help.github.com/en/github/collaborating-with-issues-and-pull-requests/creating-a-pull-request-from-a-fork).
@@ -187,15 +103,8 @@ An explanation of the `package.json` scripts.
- **`start`** Launch the app in production mode
- **`dev`** Launch the app in development mode
-- **`server`** Only launch the server
-- **`client`** Only launch the client
-- **`build`** Create a production build (No using singly)
-- **`build:netlify`** Create a production build (For the deployment of Netlify)
-- **`test`** Run tests
-
-## Note
-
-> **Fun Fact:** This project learnt a lot from [Takenote](https://github.com/taniarascia/takenote). Takenote is also awesome.
+- **`build`** Create a production build
+- **`lint`** Run ESLint
## LICENSE
diff --git a/app/api/auth/route.ts b/app/api/auth/route.ts
index 8516e50..ae3388f 100644
--- a/app/api/auth/route.ts
+++ b/app/api/auth/route.ts
@@ -1,13 +1,11 @@
/* eslint-disable no-console */
-import fs from "node:fs";
-import path from "node:path";
-
import { NextRequest } from "next/server";
import md5 from "md5";
import { generateToken, validateToken } from "@/lib/token";
import { tokenStorageKey } from "@/lib/global";
import { packet, error } from "@/lib/packet";
+import { getPasswordFromEnv, setPasswordToEnv } from "@/lib/auth";
interface AuthPostRequestData {
password: string
@@ -22,7 +20,7 @@ export async function POST(req: NextRequest) {
if(!password) return error(400);
const md5Password = md5(password);
- if(md5Password !== process.env["PASSWORD"]) return error(401);
+ if(md5Password !== getPasswordFromEnv()) return error(401);
const token = generateToken(md5Password);
return packet({ token });
@@ -50,11 +48,11 @@ export async function PATCH(req: NextRequest) {
if(!oldPassword) return error(400);
const md5OldPassword = md5(oldPassword);
- if(md5OldPassword !== process.env["PASSWORD"]) return error(401);
+ if(md5OldPassword !== getPasswordFromEnv()) return error(401);
const md5NewPassword = md5(newPassword);
- fs.writeFileSync(path.join(process.cwd(), ".env"), `PASSWORD=${md5NewPassword}`, "utf-8");
+ setPasswordToEnv(md5NewPassword);
return packet({});
} catch (err) {
diff --git a/components/dashboard/disk-widget.tsx b/components/dashboard/disk-widget.tsx
index fe1453e..38f46a5 100644
--- a/components/dashboard/disk-widget.tsx
+++ b/components/dashboard/disk-widget.tsx
@@ -67,17 +67,15 @@ const DiskWidget: React.FC = (props) => {
-
+
);
})
diff --git a/hooks/useFerrum.ts b/hooks/useFerrum.ts
index a102fd2..1b630f1 100644
--- a/hooks/useFerrum.ts
+++ b/hooks/useFerrum.ts
@@ -13,5 +13,5 @@ export const useFerrum = create((set, get) => ({
disks: [],
setDisks: (disks) => set({ disks }),
- getMountedList: () => get().disks.map((disk) => disk._mounted),
+ getMountedList: () => get().disks.map((disk) => disk.mount),
}));
diff --git a/lib/auth.ts b/lib/auth.ts
new file mode 100644
index 0000000..3a42a30
--- /dev/null
+++ b/lib/auth.ts
@@ -0,0 +1,14 @@
+import fs from "fs";
+import path from "path";
+
+const envPath = path.join(process.cwd(), ".pwd");
+
+export function getPasswordFromEnv(): string {
+ const env = fs.readFileSync(envPath, "utf-8");
+
+ return env.replace("PASSWORD=", "");
+}
+
+export function setPasswordToEnv(password: string) {
+ fs.writeFileSync(envPath, `PASSWORD=${password}`, "utf-8");
+}
diff --git a/lib/global.ts b/lib/global.ts
index a5793c3..7556723 100644
--- a/lib/global.ts
+++ b/lib/global.ts
@@ -1,4 +1,4 @@
-export const version = "0.0.1";
+export const version = "2.0.0a1";
export const tokenStorageKey = "ferrum-token";
export const diskStorageKey = "ferrum-disk";
export const starListStorageKey = "ferrum-starred";
diff --git a/lib/token.ts b/lib/token.ts
index 8b4bcc6..f77315a 100644
--- a/lib/token.ts
+++ b/lib/token.ts
@@ -1,11 +1,13 @@
import md5 from "md5";
+import { getPasswordFromEnv } from "./auth";
+
export function generateToken(password: string): string {
return password + md5(password);
}
export function validateToken(token: string): boolean {
- const password = process.env["PASSWORD"];
+ const password = getPasswordFromEnv();
if(!password) throw new Error("No environment variable: `PASSWORD`");
diff --git a/package.json b/package.json
index e0c8bda..3a8317e 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "ferrum",
- "version": "0.0.1",
+ "version": "2.0.0a1",
"private": true,
"scripts": {
"dev": "next dev -p 3300",