Compare commits
13 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
f5dec2a0a7
|
|||
|
da59740b47
|
|||
|
cae07f55cd
|
|||
|
84cf09e61b
|
|||
|
36c1990e5e
|
|||
|
21e51756f0
|
|||
|
caf8b47ca0
|
|||
|
51e5f2d0fb
|
|||
|
b0280767cb
|
|||
|
85f25a38ae
|
|||
|
00399785d4
|
|||
|
f3e69b032f
|
|||
|
cb5c752f8f
|
68
.github/workflows/build.yml
vendored
Normal file
68
.github/workflows/build.yml
vendored
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
# This is a basic workflow to help you get started with Actions
|
||||||
|
|
||||||
|
name: CI
|
||||||
|
|
||||||
|
# Controls when the workflow will run
|
||||||
|
on:
|
||||||
|
# Triggers the workflow on push or pull request events but only for the "master" branch
|
||||||
|
push:
|
||||||
|
branches: [ "master" ]
|
||||||
|
pull_request:
|
||||||
|
branches: [ "master" ]
|
||||||
|
|
||||||
|
# Allows you to run this workflow manually from the Actions tab
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
|
||||||
|
jobs:
|
||||||
|
build-backend-linux:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
- uses: actions/setup-go@v3
|
||||||
|
with:
|
||||||
|
go-version: 1.18
|
||||||
|
- name: Build linux backend
|
||||||
|
run: |
|
||||||
|
make linux
|
||||||
|
- name: Upload linux backend
|
||||||
|
uses: actions/upload-artifact@v3
|
||||||
|
with:
|
||||||
|
name: backend-linux
|
||||||
|
path: |
|
||||||
|
msw-open-music
|
||||||
|
config.json
|
||||||
|
build-backend-windows:
|
||||||
|
runs-on: windows-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
- uses: actions/setup-go@v3
|
||||||
|
with:
|
||||||
|
go-version: 1.18
|
||||||
|
- name: Build windows backend
|
||||||
|
run: |
|
||||||
|
go build -v
|
||||||
|
- name: Upload linux backend
|
||||||
|
uses: actions/upload-artifact@v3
|
||||||
|
with:
|
||||||
|
name: backend-windows
|
||||||
|
path: |
|
||||||
|
msw-open-music.exe
|
||||||
|
config.json
|
||||||
|
build-frontend-web:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
env:
|
||||||
|
CI: false
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
- uses: actions/setup-node@v3
|
||||||
|
with:
|
||||||
|
node-version: 16
|
||||||
|
- name: Build web front end
|
||||||
|
run: |
|
||||||
|
make web
|
||||||
|
- name: upload packaged front end
|
||||||
|
uses: actions/upload-artifact@v3
|
||||||
|
with:
|
||||||
|
name: frontend-web
|
||||||
|
path: web/build
|
||||||
3
Makefile
3
Makefile
@@ -1,4 +1,5 @@
|
|||||||
dist:
|
.PHONY: web linux windows
|
||||||
|
web:
|
||||||
cd web && npm install
|
cd web && npm install
|
||||||
cd web && npm run build
|
cd web && npm run build
|
||||||
|
|
||||||
|
|||||||
137
README-cn.md
Normal file
137
README-cn.md
Normal file
@@ -0,0 +1,137 @@
|
|||||||
|
# MSW Open Music Project
|
||||||
|
|
||||||
|
[](https://github.com/heimoshuiyu/msw-open-music/actions/workflows/build.yml)
|
||||||
|
|
||||||
|
🔴 演示 Demo: <https://msw-open-music.live>
|
||||||
|
|
||||||
|
> 找一首歌最好的方法是:打开一个超长的歌单,然后随机播放,直到你找到为止。
|
||||||
|
|
||||||
|
一个 💪 轻量级 ⚡️ 高性能 🖥️ 跨平台的 个人音乐串流平台。管理你现有的音乐文件并在其他设备上播放。
|
||||||
|
|
||||||
|
前端网页应用基于 `react.js` 和 `water.css` 构建。后端服务器程序使用 `golang` 和 `sqlite` 构建。
|
||||||
|
|
||||||
|
## 介绍
|
||||||
|
|
||||||
|
截图
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
### 功能特点
|
||||||
|
|
||||||
|
- 🔎 索引现有的音乐文件,并记录文件名和文件夹元信息
|
||||||
|
|
||||||
|
- 📕 使用 文件夹 📁 标签 🏷️ 评论 💬 来管理你的音乐。
|
||||||
|
|
||||||
|
- 🌐 提供一个轻量高效的网页前端并支持多种语言。
|
||||||
|
|
||||||
|
- 👥 支持多用户。
|
||||||
|
|
||||||
|
- 🔥 调用 `ffmpeg` 配合可自定义的预设配置来转码你的音乐。
|
||||||
|
|
||||||
|
- 🔗 分享音乐链接给好友!
|
||||||
|
|
||||||
|
### 如果你遇到过这样的烦恼...你就是目标用户
|
||||||
|
|
||||||
|
- 硬盘上存了一堆音乐,但没有一个很好的播放器. 🖴
|
||||||
|
|
||||||
|
- 下载了体积非常大的无损音乐,在设备间移动很困难. 🎵
|
||||||
|
|
||||||
|
- 想要在其他 电脑/手机 上听 电脑/服务器 上储存的音乐. 😋
|
||||||
|
|
||||||
|
- 想给你的好友分享本地音乐. 😘
|
||||||
|
|
||||||
|
## 使用方法
|
||||||
|
|
||||||
|
1. 修改 `config.json` 配置文件中的 `secret` 值
|
||||||
|
|
||||||
|
2. 运行后端服务器程序 `msw-open-music.exe` 或者 `msw-open-music`. 服务默认监听 8080 端口。 然后打开 <http://127.0.0.1:8080> 去创建的一个管理员帐号。
|
||||||
|
|
||||||
|
前端 HTML 文件存放在 `web/build` 目录下。
|
||||||
|
|
||||||
|
### 创建第一个管理员帐号
|
||||||
|
|
||||||
|
第一个创建的管理员帐号会被自动激活,其他后续创建的管理员帐号需要管理员手动激活。
|
||||||
|
|
||||||
|
请前往注册页面,选择角色为 管理员,然后注册第一个管理员帐号。
|
||||||
|
|
||||||
|
#### config.json
|
||||||
|
|
||||||
|
- `secret` 字符串类型。用来加密 session 会话。
|
||||||
|
|
||||||
|
- `database_name` 字符串类型。`sqlite3` 数据库的文件名。如果不存在,会自动创建。
|
||||||
|
- `addr` 字符串类型。监听地址和端口。
|
||||||
|
- `ffmpeg_config_list` 列表类型。预设的 `ffmpeg` 配置文件。包含 `ffmpegConfig` 对象。
|
||||||
|
- `file_life_time` 整数类型(秒)。临时文件的生命周期。如果临时文件超过这个时间没有被访问,那么将会被自动删除。
|
||||||
|
- `cleaner_internal` 整数类型(秒)。`tmpfs` 检查临时文件的间隔时间。
|
||||||
|
- `root` 字符串类型。存放临时文件的目录。默认是 `/tmp`。**Windows用户请修改成可用的目录**。如果不存在,将会被自动创建。
|
||||||
|
- `permission` 各个 API 的权限等级。
|
||||||
|
- `0` 无需任何权限。
|
||||||
|
- `1` 需要管理员(最高级别)权限等级。
|
||||||
|
- `2` 需要普通用户权限等级,也就是说,管理员和普通用户都有权访问此等级的 API ,而 匿名用户 则没有权限访问。
|
||||||
|
- 如果你想避免 API 被滥用,可以调整下面 5 个与串流相关的 API 权限等级。
|
||||||
|
- `/get_file` 使用 `io.copy()` 方法串流
|
||||||
|
- `/get_file_direct` 使用 `http.serveFile()` 方法串流
|
||||||
|
- `/get_file_stream` 调用 `ffmpeg` 并串流其标准输出 `stdout`
|
||||||
|
- `/prepare_file_stream_direct` 调用 `ffmpeg` 预转码一个文件
|
||||||
|
- `/get_file_stream_direct` 使用 `http.serveFile()` 获取预转码结束的临时文件
|
||||||
|
- 其他在 `config.json` 中没有设定的 API 将默认拥有 `0` 的权限等级。
|
||||||
|
|
||||||
|
对于 Windows 用户,请确保 `ffmpeg` 正确安装并设置环境变量。
|
||||||
|
|
||||||
|
## 开发
|
||||||
|
|
||||||
|
欢迎任何 issue / pull request / feature request
|
||||||
|
|
||||||
|
### 主要变更历史
|
||||||
|
|
||||||
|
- `v1.0.0` 第一个版本。核心串流功能可用。
|
||||||
|
- `v1.1.0` 使用 `React` 重构前端。
|
||||||
|
- `v1.2.0` 数据库 DBMS 课程作业。添加 用户、标签、评论 和其他功能。
|
||||||
|
|
||||||
|
### ER Diagram
|
||||||
|
|
||||||
|
Database Entities Relationship Diagram
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
- `avatar` 目前没有在使用。
|
||||||
|
|
||||||
|
- 第一次运行程序时,程序会自动创建一个 ID 为 `1` 的匿名用户。所有未登陆的用户都会自动登陆到这个账户。
|
||||||
|
|
||||||
|
- `tmpfs` 储存在内存中,每次重新启动后端程序将会清空记录的信息。
|
||||||
|
|
||||||
|
### 关于 tmpfs
|
||||||
|
|
||||||
|
如果前端的播放器勾选了 `预转码` 选项,后端程序会先将文件转码到临时目录中,转码完成后再串流文件。这么做可以实现断点续传,解决由于网络波动导致 `ffmpeg` 管道链接断开而终止转码的问题。
|
||||||
|
|
||||||
|
默认的临时文件夹目录是 `/tmp`,这是 Linux 系统中通用的临时目录。默认的生存时间是 600 秒(10 分钟)。如果超过这个时间没有访问该临时文件,那么后端程序将会自动删除它。
|
||||||
|
|
||||||
|
### 后端 API 设计
|
||||||
|
|
||||||
|
一个不需要返回任何有用数据的 API 将会返回下面的 JSON 对象
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"status": "OK"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
当错误发生时,后端会返回如下格式的 JSON 对象。`error` 是对错误信息的详细描述文本。
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"error": "Wrong password"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
不需要传递参数的 API 使用 `GET` 方法,否则使用 `POST` 方法。(忽略 RESTFUL 设计)
|
||||||
|
|
||||||
|
后端使用 cookies 来实现用户会话管理。任何不带 cookies 的请求会被认为是由 匿名用户 发送的(也就是 ID 为 `1` 的用户)
|
||||||
|
|
||||||
|
一些重要的源代码文件
|
||||||
|
|
||||||
|
- `pkg/api/api.go` 定义各个 API 的 URL 和对应函数。
|
||||||
|
|
||||||
|
- `pkg/database/sql_stmt.go` 定义 SQL 语句和做一些初始化工作。
|
||||||
|
|
||||||
|
- `pkg/database/struct.go` 定义 JSON 和 数据库对象 的 数据结构。
|
||||||
17
README.md
17
README.md
@@ -1,5 +1,11 @@
|
|||||||
# MSW Open Music Project
|
# MSW Open Music Project
|
||||||
|
|
||||||
|
[](https://github.com/heimoshuiyu/msw-open-music/actions/workflows/build.yml)
|
||||||
|
|
||||||
|
🔴 Demo: <https://msw-open-music.live>
|
||||||
|
|
||||||
|
[中文文档](./README-cn.md)
|
||||||
|
|
||||||
> The best way to search for a music is to load up a huge playlist and shuffle until you find it.
|
> The best way to search for a music is to load up a huge playlist and shuffle until you find it.
|
||||||
|
|
||||||
A 💪 light weight ⚡️ blazingly fast 🖥️ cross platform personal music streaming platform. Manage your existing music files and enjoy them on any devices.
|
A 💪 light weight ⚡️ blazingly fast 🖥️ cross platform personal music streaming platform. Manage your existing music files and enjoy them on any devices.
|
||||||
@@ -60,6 +66,17 @@ Go to register page, select the role to admin, and register the first admin acco
|
|||||||
- `file_life_time` integer type (second). Life time for temporary file. If the temporary file is not accessed for more than this time, back-end server will delete this file.
|
- `file_life_time` integer type (second). Life time for temporary file. If the temporary file is not accessed for more than this time, back-end server will delete this file.
|
||||||
- `cleaner_internal` integer type (second). Interval for `tmpfs` checking temporary file.
|
- `cleaner_internal` integer type (second). Interval for `tmpfs` checking temporary file.
|
||||||
- `root` string type. Directory to store temporary files. Default is `/tmp`, **please modify this directory if you are using Windows.** Directory will be created if not exists.
|
- `root` string type. Directory to store temporary files. Default is `/tmp`, **please modify this directory if you are using Windows.** Directory will be created if not exists.
|
||||||
|
- `permission`. Specify each API's permission level.
|
||||||
|
- `0` for no permission required.
|
||||||
|
- `1` require admin level (highest level) permission.
|
||||||
|
- `2` require normal user level permission. That is, both admins and registered users can access to this URL, except anonymous users.
|
||||||
|
- If you want to avoid abuse of the playback API, you can adjust the permission level for these 5 playback-related APIs.
|
||||||
|
- `/get_file` get file with `io.copy()` method
|
||||||
|
- `/get_file_direct` get file with `http.serveFile()` method
|
||||||
|
- `/get_file_stream` call ffmpeg and stream its `stdout` output
|
||||||
|
- `/prepare_file_stream_direct` call ffmpeg to convert a file
|
||||||
|
- `/get_file_stream_direct` get the converted file with `http.serveFile()`
|
||||||
|
- Other URLs not metion in `config.json` will have `0` permission level by default.
|
||||||
|
|
||||||
For windows user, make sure you have `ffmpeg` installed.
|
For windows user, make sure you have `ffmpeg` installed.
|
||||||
|
|
||||||
|
|||||||
35
config.json
35
config.json
@@ -38,8 +38,39 @@
|
|||||||
},
|
},
|
||||||
{ "name": "MP3 128k", "args": "-c:a mp3 -ab 128k -vn", "format": "mp3" },
|
{ "name": "MP3 128k", "args": "-c:a mp3 -ab 128k -vn", "format": "mp3" },
|
||||||
{ "name": "MP3 320k", "args": "-c:a mp3 -ab 320k -vn", "format": "mp3" },
|
{ "name": "MP3 320k", "args": "-c:a mp3 -ab 320k -vn", "format": "mp3" },
|
||||||
{ "name": "全损音质 8k", "args": "-c:a libopus -ab 8k -vn", "format": "webm" }
|
{
|
||||||
]
|
"name": "全损音质 8k",
|
||||||
|
"args": "-c:a libopus -ab 8k -vn",
|
||||||
|
"format": "webm"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"permission": {
|
||||||
|
"/register": 0,
|
||||||
|
"/get_file": 0,
|
||||||
|
"/get_file_direct": 0,
|
||||||
|
"/get_file_stream": 0,
|
||||||
|
"/prepare_file_stream_direct": 0,
|
||||||
|
"/get_file_stream_direct": 0,
|
||||||
|
"/walk": 1,
|
||||||
|
"/reset": 1,
|
||||||
|
"/update_user_active": 1,
|
||||||
|
"/get_feedbacks": 1,
|
||||||
|
"/delete_feedback": 1,
|
||||||
|
"/delete_file": 1,
|
||||||
|
"/update_filename": 1,
|
||||||
|
"/reset_filename": 1,
|
||||||
|
"/reset_foldername": 1,
|
||||||
|
"/update_foldername": 1,
|
||||||
|
"/insert_tag": 1,
|
||||||
|
"/update_tag": 1,
|
||||||
|
"/delete_tag": 1,
|
||||||
|
"/put_tag_on_file": 1,
|
||||||
|
"/delete_tag_on_file": 1,
|
||||||
|
"/delete_review": 2,
|
||||||
|
"/update_review": 2,
|
||||||
|
"/update_user_password": 2,
|
||||||
|
"/update_username": 2
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"tmpfs": {
|
"tmpfs": {
|
||||||
"file_life_time": 600,
|
"file_life_time": 600,
|
||||||
|
|||||||
@@ -1,36 +0,0 @@
|
|||||||
# DBMS Group Project Problem Description
|
|
||||||
|
|
||||||
- Group 1
|
|
||||||
|
|
||||||
The Internet infrastructure construction has made the network speed development faster. With the fast Internet, people are gradually migrating various data and services to the cloud. For example, NetEase Cloud Music, Spotify, and Apple Music, we call them streaming media platforms. The definition of streaming media platform is that users purchase the digital copyright of music and then play the music online on the platform.
|
|
||||||
|
|
||||||
Generally speaking, users cannot buy music that is not available on the platform. The user cannot download the digital file of the music (the user purchases the right to play instead of the right to copy). Users cannot upload their music to the platform.
|
|
||||||
|
|
||||||
However, in the era of digital copyright, there are still many advantages to getting original music files, such as no need to install a dedicated player; free copying to other devices (without violating copyright); no risk of music unavailable from the platform; no play records and privacy will be tracked by the platform.
|
|
||||||
|
|
||||||
Some people don't like streaming platforms. They like to collect music (download or buy CDs) and save it on their computers. But as more and more music is collected (over 70,000 songs and in total size of 800GB), it becomes very difficult to manage files. It is difficult for them to find where the songs they want to listen to are saved. Also, lossless music files are large and difficult to play online.
|
|
||||||
|
|
||||||
As long as there no such "Self-hosted music streaming platform" software available, we decided to develop a project based on database knowledge to help people who have collected a lot of music to enjoy their music simply.
|
|
||||||
|
|
||||||
We will handle various relevant types of data in our database. Including song name, album name, file size, update date, rating, comment, user information, etc. They are highly relevant, so using a relational database will be a good choice.
|
|
||||||
|
|
||||||
The features of the project we designed are as follows:
|
|
||||||
|
|
||||||
- Open. Independent front-end (GUI) and back-end (server program), using API to communicate.
|
|
||||||
- Easy to use. Minimize dependencies, allowing users to configure quickly and simply.
|
|
||||||
- Lightweight. The program is small in size and quick to install.
|
|
||||||
- High performance. Only do what should be done, no features that will lead to poor performance.
|
|
||||||
- Cross-platform. The project can run on computers, mobile phones, Linux, Windows, macOS, and X86 and ARM processor architectures.
|
|
||||||
- Extensibility. Access to cloud OSS (Object Storage Service), reverse proxy, or other external software.
|
|
||||||
|
|
||||||
Our project has the following functions:
|
|
||||||
|
|
||||||
- Index file. Index local files into the database.
|
|
||||||
- Search. Search for music based on name/album/tag/comment, sorted by rating or other columns.
|
|
||||||
- Play. Play music online, play music randomly and play music at a low bit rate on a bad network.
|
|
||||||
- User management. Users can register and log in.
|
|
||||||
- Comment. Users can give a like or comment on the music.
|
|
||||||
- Management. The administrator can upload music, update or delete the database.
|
|
||||||
- Share. Generate a link to share the music with others.
|
|
||||||
|
|
||||||
After research and discussion, in order to meet the above requirements, we decided to use the Golang programming language on the backend. SQLite as a database program. Vue as the front-end GUI interface.
|
|
||||||
@@ -94,11 +94,11 @@ func NewAPI(config commonconfig.Config) (*API, error) {
|
|||||||
apiMux.HandleFunc("/update_review", api.HandleUpdateReview)
|
apiMux.HandleFunc("/update_review", api.HandleUpdateReview)
|
||||||
apiMux.HandleFunc("/delete_review", api.HandleDeleteReview)
|
apiMux.HandleFunc("/delete_review", api.HandleDeleteReview)
|
||||||
apiMux.HandleFunc("/get_reviews_by_user", api.HandleGetReviewsByUser)
|
apiMux.HandleFunc("/get_reviews_by_user", api.HandleGetReviewsByUser)
|
||||||
// below needs admin
|
// database
|
||||||
apiMux.HandleFunc("/walk", api.HandleWalk)
|
apiMux.HandleFunc("/walk", api.HandleWalk)
|
||||||
apiMux.HandleFunc("/reset", api.HandleReset)
|
apiMux.HandleFunc("/reset", api.HandleReset)
|
||||||
|
|
||||||
mux.Handle("/api/v1/", http.StripPrefix("/api/v1", apiMux))
|
mux.Handle("/api/v1/", http.StripPrefix("/api/v1", api.PermissionMiddleware(apiMux)))
|
||||||
mux.Handle("/", http.StripPrefix("/", http.FileServer(http.Dir("web/build"))))
|
mux.Handle("/", http.StripPrefix("/", http.FileServer(http.Dir("web/build"))))
|
||||||
|
|
||||||
return api, nil
|
return api, nil
|
||||||
|
|||||||
@@ -14,12 +14,6 @@ type WalkRequest struct {
|
|||||||
|
|
||||||
func (api *API) HandleReset(w http.ResponseWriter, r *http.Request) {
|
func (api *API) HandleReset(w http.ResponseWriter, r *http.Request) {
|
||||||
var err error
|
var err error
|
||||||
// check admin
|
|
||||||
err = api.CheckAdmin(w, r)
|
|
||||||
if err != nil {
|
|
||||||
api.HandleError(w, r, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
log.Println("[api] Reset database")
|
log.Println("[api] Reset database")
|
||||||
|
|
||||||
@@ -46,13 +40,6 @@ func (api *API) HandleWalk(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// check admin
|
|
||||||
err = api.CheckAdmin(w, r)
|
|
||||||
if err != nil {
|
|
||||||
api.HandleError(w, r, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// check root empty
|
// check root empty
|
||||||
if walkRequest.Root == "" {
|
if walkRequest.Root == "" {
|
||||||
api.HandleErrorString(w, r, `key "root" can't be empty`)
|
api.HandleErrorString(w, r, `key "root" can't be empty`)
|
||||||
|
|||||||
@@ -56,13 +56,6 @@ type GetFeedbacksResponse struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (api *API) HandleGetFeedbacks(w http.ResponseWriter, r *http.Request) {
|
func (api *API) HandleGetFeedbacks(w http.ResponseWriter, r *http.Request) {
|
||||||
// check if admin
|
|
||||||
err := api.CheckAdmin(w, r)
|
|
||||||
if err != nil {
|
|
||||||
api.HandleError(w, r, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
feedbacks, err := api.Db.GetFeedbacks()
|
feedbacks, err := api.Db.GetFeedbacks()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
api.HandleError(w, r, err)
|
api.HandleError(w, r, err)
|
||||||
@@ -85,15 +78,8 @@ type DeleteFeedbackRequest struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (api *API) HandleDeleteFeedback(w http.ResponseWriter, r *http.Request) {
|
func (api *API) HandleDeleteFeedback(w http.ResponseWriter, r *http.Request) {
|
||||||
// check if admin
|
|
||||||
err := api.CheckAdmin(w, r)
|
|
||||||
if err != nil {
|
|
||||||
api.HandleError(w, r, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
req := &DeleteFeedbackRequest{}
|
req := &DeleteFeedbackRequest{}
|
||||||
err = json.NewDecoder(r.Body).Decode(req)
|
err := json.NewDecoder(r.Body).Decode(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
api.HandleError(w, r, err)
|
api.HandleError(w, r, err)
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -11,15 +11,8 @@ type DeleteFileRequest struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (api *API) HandleDeleteFile(w http.ResponseWriter, r *http.Request) {
|
func (api *API) HandleDeleteFile(w http.ResponseWriter, r *http.Request) {
|
||||||
// check admin
|
|
||||||
err := api.CheckAdmin(w, r)
|
|
||||||
if err != nil {
|
|
||||||
api.HandleError(w, r, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
req := &DeleteFileRequest{}
|
req := &DeleteFileRequest{}
|
||||||
err = json.NewDecoder(r.Body).Decode(req)
|
err := json.NewDecoder(r.Body).Decode(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
api.HandleError(w, r, err)
|
api.HandleError(w, r, err)
|
||||||
return
|
return
|
||||||
@@ -42,15 +35,8 @@ type UpdateFilenameRequest struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (api *API) HandleUpdateFilename(w http.ResponseWriter, r *http.Request) {
|
func (api *API) HandleUpdateFilename(w http.ResponseWriter, r *http.Request) {
|
||||||
// check admin
|
|
||||||
err := api.CheckAdmin(w, r)
|
|
||||||
if err != nil {
|
|
||||||
api.HandleError(w, r, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
req := &UpdateFilenameRequest{}
|
req := &UpdateFilenameRequest{}
|
||||||
err = json.NewDecoder(r.Body).Decode(req)
|
err := json.NewDecoder(r.Body).Decode(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
api.HandleError(w, r, err)
|
api.HandleError(w, r, err)
|
||||||
return
|
return
|
||||||
@@ -72,15 +58,8 @@ type ResetFilenameRequest struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (api *API) HandleResetFilename(w http.ResponseWriter, r *http.Request) {
|
func (api *API) HandleResetFilename(w http.ResponseWriter, r *http.Request) {
|
||||||
// check admin
|
|
||||||
err := api.CheckAdmin(w, r)
|
|
||||||
if err != nil {
|
|
||||||
api.HandleError(w, r, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
req := &ResetFilenameRequest{}
|
req := &ResetFilenameRequest{}
|
||||||
err = json.NewDecoder(r.Body).Decode(req)
|
err := json.NewDecoder(r.Body).Decode(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
api.HandleError(w, r, err)
|
api.HandleError(w, r, err)
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -11,15 +11,8 @@ type ResetFoldernameRequest struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (api *API) HandleResetFoldername(w http.ResponseWriter, r *http.Request) {
|
func (api *API) HandleResetFoldername(w http.ResponseWriter, r *http.Request) {
|
||||||
// check admin
|
|
||||||
err := api.CheckAdmin(w, r)
|
|
||||||
if err != nil {
|
|
||||||
api.HandleError(w, r, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
req := &ResetFoldernameRequest{}
|
req := &ResetFoldernameRequest{}
|
||||||
err = json.NewDecoder(r.Body).Decode(req)
|
err := json.NewDecoder(r.Body).Decode(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, err.Error(), http.StatusBadRequest)
|
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
@@ -49,13 +42,6 @@ func (api *API) HandleUpdateFoldername(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// check is admin
|
|
||||||
err = api.CheckAdmin(w, r)
|
|
||||||
if err != nil {
|
|
||||||
api.HandleError(w, r, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
log.Println("[api] Update foldername folderID", req.ID, req.Foldername)
|
log.Println("[api] Update foldername folderID", req.ID, req.Foldername)
|
||||||
|
|
||||||
err = api.Db.UpdateFoldername(req.ID, req.Foldername)
|
err = api.Db.UpdateFoldername(req.ID, req.Foldername)
|
||||||
|
|||||||
@@ -116,13 +116,8 @@ func (api *API) CheckUserCanModifyReview(w http.ResponseWriter, r *http.Request,
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = api.CheckNotAnonymous(w, r)
|
userLevel := api.GetUserLevel(r)
|
||||||
if err != nil {
|
if userLevel != database.RoleAdmin {
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
err = api.CheckAdmin(w, r)
|
|
||||||
if err != nil {
|
|
||||||
userID, err := api.GetUserID(w, r)
|
userID, err := api.GetUserID(w, r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|||||||
@@ -34,15 +34,8 @@ type InsertTagResponse struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (api *API) HandleInsertTag(w http.ResponseWriter, r *http.Request) {
|
func (api *API) HandleInsertTag(w http.ResponseWriter, r *http.Request) {
|
||||||
// check if user is admin
|
|
||||||
err := api.CheckAdmin(w, r)
|
|
||||||
if err != nil {
|
|
||||||
api.HandleError(w, r, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
req := &database.Tag{}
|
req := &database.Tag{}
|
||||||
err = json.NewDecoder(r.Body).Decode(&req)
|
err := json.NewDecoder(r.Body).Decode(&req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
api.HandleError(w, r, err)
|
api.HandleError(w, r, err)
|
||||||
return
|
return
|
||||||
@@ -107,15 +100,8 @@ func (api *API) HandleGetTagInfo(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (api *API) HandleUpdateTag(w http.ResponseWriter, r *http.Request) {
|
func (api *API) HandleUpdateTag(w http.ResponseWriter, r *http.Request) {
|
||||||
// check if user is admin
|
|
||||||
err := api.CheckAdmin(w, r)
|
|
||||||
if err != nil {
|
|
||||||
api.HandleError(w, r, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
req := &database.Tag{}
|
req := &database.Tag{}
|
||||||
err = json.NewDecoder(r.Body).Decode(req)
|
err := json.NewDecoder(r.Body).Decode(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
api.HandleError(w, r, err)
|
api.HandleError(w, r, err)
|
||||||
return
|
return
|
||||||
@@ -135,15 +121,8 @@ type DeleteTagRequest struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (api *API) HandleDeleteTag(w http.ResponseWriter, r *http.Request) {
|
func (api *API) HandleDeleteTag(w http.ResponseWriter, r *http.Request) {
|
||||||
// check if user is admin
|
|
||||||
err := api.CheckAdmin(w, r)
|
|
||||||
if err != nil {
|
|
||||||
api.HandleError(w, r, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
req := &DeleteTagRequest{}
|
req := &DeleteTagRequest{}
|
||||||
err = json.NewDecoder(r.Body).Decode(req)
|
err := json.NewDecoder(r.Body).Decode(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
api.HandleError(w, r, err)
|
api.HandleError(w, r, err)
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -13,15 +13,8 @@ type PutTagOnFileRequest struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (api *API) HandlePutTagOnFile(w http.ResponseWriter, r *http.Request) {
|
func (api *API) HandlePutTagOnFile(w http.ResponseWriter, r *http.Request) {
|
||||||
// check if the user is admin
|
|
||||||
err := api.CheckAdmin(w, r)
|
|
||||||
if err != nil {
|
|
||||||
api.HandleError(w, r, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
req := &PutTagOnFileRequest{}
|
req := &PutTagOnFileRequest{}
|
||||||
err = json.NewDecoder(r.Body).Decode(req)
|
err := json.NewDecoder(r.Body).Decode(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
api.HandleError(w, r, err)
|
api.HandleError(w, r, err)
|
||||||
return
|
return
|
||||||
@@ -87,15 +80,8 @@ type DeleteTagOnFileRequest struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (api *API) HandleDeleteTagOnFile(w http.ResponseWriter, r *http.Request) {
|
func (api *API) HandleDeleteTagOnFile(w http.ResponseWriter, r *http.Request) {
|
||||||
// check if the user is admin
|
|
||||||
err := api.CheckAdmin(w, r)
|
|
||||||
if err != nil {
|
|
||||||
api.HandleError(w, r, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
req := &DeleteTagOnFileRequest{}
|
req := &DeleteTagOnFileRequest{}
|
||||||
err = json.NewDecoder(r.Body).Decode(req)
|
err := json.NewDecoder(r.Body).Decode(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
api.HandleError(w, r, err)
|
api.HandleError(w, r, err)
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -142,44 +142,6 @@ func (api *API) HandleRegister(w http.ResponseWriter, r *http.Request) {
|
|||||||
api.HandleOK(w, r)
|
api.HandleOK(w, r)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (api *API) CheckAdmin(w http.ResponseWriter, r *http.Request) error {
|
|
||||||
session, _ := api.store.Get(r, api.defaultSessionName)
|
|
||||||
userId, ok := session.Values["userId"]
|
|
||||||
if !ok {
|
|
||||||
return ErrNotLoggedIn
|
|
||||||
}
|
|
||||||
|
|
||||||
user, err := api.Db.GetUserById(userId.(int64))
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if user.Role != database.RoleAdmin {
|
|
||||||
return ErrNotAdmin
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (api *API) CheckNotAnonymous(w http.ResponseWriter, r *http.Request) error {
|
|
||||||
session, _ := api.store.Get(r, api.defaultSessionName)
|
|
||||||
userId, ok := session.Values["userId"]
|
|
||||||
if !ok {
|
|
||||||
return ErrNotLoggedIn
|
|
||||||
}
|
|
||||||
|
|
||||||
user, err := api.Db.GetUserById(userId.(int64))
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if user.Role == database.RoleAnonymous {
|
|
||||||
return ErrAnonymous
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (api *API) GetUserID(w http.ResponseWriter, r *http.Request) (int64, error) {
|
func (api *API) GetUserID(w http.ResponseWriter, r *http.Request) (int64, error) {
|
||||||
session, _ := api.store.Get(r, api.defaultSessionName)
|
session, _ := api.store.Get(r, api.defaultSessionName)
|
||||||
userId, ok := session.Values["userId"]
|
userId, ok := session.Values["userId"]
|
||||||
@@ -218,14 +180,8 @@ type UpdateUserActiveRequest struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (api *API) HandleUpdateUserActive(w http.ResponseWriter, r *http.Request) {
|
func (api *API) HandleUpdateUserActive(w http.ResponseWriter, r *http.Request) {
|
||||||
err := api.CheckAdmin(w, r)
|
|
||||||
if err != nil {
|
|
||||||
api.HandleError(w, r, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
req := &UpdateUserActiveRequest{}
|
req := &UpdateUserActiveRequest{}
|
||||||
err = json.NewDecoder(r.Body).Decode(req)
|
err := json.NewDecoder(r.Body).Decode(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
api.HandleError(w, r, err)
|
api.HandleError(w, r, err)
|
||||||
return
|
return
|
||||||
@@ -245,16 +201,11 @@ type UpdateUsernameRequest struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (api *API) HandleUpdateUsername(w http.ResponseWriter, r *http.Request) {
|
func (api *API) HandleUpdateUsername(w http.ResponseWriter, r *http.Request) {
|
||||||
// reject anonymous user
|
// middileware reject anonymous user
|
||||||
err := api.CheckNotAnonymous(w, r)
|
|
||||||
if err != nil {
|
|
||||||
api.HandleError(w, r, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
req := &UpdateUsernameRequest{}
|
req := &UpdateUsernameRequest{}
|
||||||
|
|
||||||
err = json.NewDecoder(r.Body).Decode(req)
|
err := json.NewDecoder(r.Body).Decode(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
api.HandleError(w, r, err)
|
api.HandleError(w, r, err)
|
||||||
return
|
return
|
||||||
@@ -326,15 +277,10 @@ type UpdateUserPasswordRequest struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (api *API) HandleUpdateUserPassword(w http.ResponseWriter, r *http.Request) {
|
func (api *API) HandleUpdateUserPassword(w http.ResponseWriter, r *http.Request) {
|
||||||
// reject anonymous user
|
// middleware reject anonymous user
|
||||||
err := api.CheckNotAnonymous(w, r)
|
|
||||||
if err != nil {
|
|
||||||
api.HandleError(w, r, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
req := &UpdateUserPasswordRequest{}
|
req := &UpdateUserPasswordRequest{}
|
||||||
err = json.NewDecoder(r.Body).Decode(req)
|
err := json.NewDecoder(r.Body).Decode(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
api.HandleError(w, r, err)
|
api.HandleError(w, r, err)
|
||||||
return
|
return
|
||||||
|
|||||||
55
pkg/api/middleware.go
Normal file
55
pkg/api/middleware.go
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
package api
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"net/http"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (api *API) PermissionMiddleware(next http.Handler) http.Handler {
|
||||||
|
// 0 anonymous user
|
||||||
|
// 1 admin
|
||||||
|
// 2 normal user
|
||||||
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
// get permission of URL
|
||||||
|
permission, ok := api.APIConfig.Permission[r.URL.Path]
|
||||||
|
// 0 means no permission required
|
||||||
|
if !ok || permission == 0 {
|
||||||
|
next.ServeHTTP(w, r)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// ger user permission level
|
||||||
|
userLevel := api.GetUserLevel(r)
|
||||||
|
|
||||||
|
// admin has root (highest) permission level 1
|
||||||
|
if userLevel == 1 {
|
||||||
|
next.ServeHTTP(w, r)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// anonymous userLevel 0 don't have any permission
|
||||||
|
// check permission level for other users
|
||||||
|
if userLevel == 0 || userLevel > permission {
|
||||||
|
api.HandleError(w, r, errors.New("No enougth permission"))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
next.ServeHTTP(w, r)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func (api *API) GetUserLevel(r *http.Request) int64 {
|
||||||
|
session, _ := api.store.Get(r, api.defaultSessionName)
|
||||||
|
userId, ok := session.Values["userId"]
|
||||||
|
if !ok {
|
||||||
|
// not logined user is considered anonymous user
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
user, err := api.Db.GetUserById(userId.(int64))
|
||||||
|
if err != nil {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
return user.Role
|
||||||
|
}
|
||||||
@@ -12,6 +12,7 @@ type APIConfig struct {
|
|||||||
FfmpegThreads int64 `json:"ffmpeg_threads"`
|
FfmpegThreads int64 `json:"ffmpeg_threads"`
|
||||||
FfmpegConfigList []FfmpegConfig `json:"ffmpeg_config_list"`
|
FfmpegConfigList []FfmpegConfig `json:"ffmpeg_config_list"`
|
||||||
SECRET string `json:"secret"`
|
SECRET string `json:"secret"`
|
||||||
|
Permission map[string]int64 `json:"permission"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type FfmpegConfigList struct {
|
type FfmpegConfigList struct {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "msw-open-music-react",
|
"name": "msw-open-music-react",
|
||||||
"version": "1.1.0",
|
"version": "1.2.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@testing-library/jest-dom": "^5.15.0",
|
"@testing-library/jest-dom": "^5.15.0",
|
||||||
|
|||||||
@@ -98,7 +98,7 @@ function AudioPlayer(props) {
|
|||||||
{CalcReadableFilesizeDetail(props.playingFile.filesize)}
|
{CalcReadableFilesizeDetail(props.playingFile.filesize)}
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
{isPreparing && <button disabled>Preparing...</button>}
|
{isPreparing && <button disabled>{Tr("Preparing...")}</button>}
|
||||||
|
|
||||||
{playingURL !== "" && (
|
{playingURL !== "" && (
|
||||||
<button
|
<button
|
||||||
|
|||||||
@@ -11,7 +11,12 @@ function FileDialog(props) {
|
|||||||
let navigate = useNavigate();
|
let navigate = useNavigate();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<dialog open={props.showStatus}>
|
<dialog
|
||||||
|
open={props.showStatus}
|
||||||
|
style={{
|
||||||
|
zIndex: 1,
|
||||||
|
}}
|
||||||
|
>
|
||||||
<p
|
<p
|
||||||
style={{
|
style={{
|
||||||
cursor: "pointer",
|
cursor: "pointer",
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import { useContext } from "react";
|
|||||||
function Manage(props) {
|
function Manage(props) {
|
||||||
let navigate = useNavigate();
|
let navigate = useNavigate();
|
||||||
const { langCode, setLangCode } = useContext(langCodeContext);
|
const { langCode, setLangCode } = useContext(langCodeContext);
|
||||||
const codes = Object.keys(LANG_OPTIONS);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="page">
|
<div className="page">
|
||||||
@@ -17,13 +16,18 @@ function Manage(props) {
|
|||||||
</p>
|
</p>
|
||||||
|
|
||||||
<select
|
<select
|
||||||
|
value={langCode}
|
||||||
onChange={(event) => {
|
onChange={(event) => {
|
||||||
setLangCode(codes[event.target.selectedIndex]);
|
setLangCode(event.target.value);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{codes.map((code) => {
|
{Object.keys(LANG_OPTIONS).map((code) => {
|
||||||
const langOption = LANG_OPTIONS[code];
|
const langOption = LANG_OPTIONS[code];
|
||||||
return <option key={code}>{langOption.name}</option>;
|
return (
|
||||||
|
<option value={code} key={code}>
|
||||||
|
{langOption.name}
|
||||||
|
</option>
|
||||||
|
);
|
||||||
})}
|
})}
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
@@ -80,6 +84,15 @@ function Manage(props) {
|
|||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<Database />
|
<Database />
|
||||||
|
<p>
|
||||||
|
<a
|
||||||
|
href="https://github.com/heimoshuiyu/msw-open-music"
|
||||||
|
target="_blank"
|
||||||
|
rel="noreferrer"
|
||||||
|
>
|
||||||
|
{Tr("View source code on Github")}
|
||||||
|
</a>
|
||||||
|
</p>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,13 @@
|
|||||||
import { useEffect, useState } from "react";
|
import { useContext, useEffect, useState } from "react";
|
||||||
import { useParams } from "react-router";
|
import { useParams } from "react-router";
|
||||||
import FilesTable from "./FilesTable";
|
import FilesTable from "./FilesTable";
|
||||||
import { Tr } from "../translate";
|
import { Tr, tr, langCodeContext } from "../translate";
|
||||||
|
|
||||||
function Share(props) {
|
function Share(props) {
|
||||||
let params = useParams();
|
let params = useParams();
|
||||||
const [file, setFile] = useState([]);
|
const { langCode } = useContext(langCodeContext);
|
||||||
|
|
||||||
|
const [file, setFile] = useState({});
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
fetch("/api/v1/get_file_info", {
|
fetch("/api/v1/get_file_info", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
@@ -16,12 +18,27 @@ function Share(props) {
|
|||||||
})
|
})
|
||||||
.then((response) => response.json())
|
.then((response) => response.json())
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
setFile([data]);
|
setFile(data);
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
alert("get_file_info error: " + error);
|
alert("get_file_info error: " + error);
|
||||||
});
|
});
|
||||||
}, [params]);
|
}, [params]);
|
||||||
|
|
||||||
|
// change title
|
||||||
|
useEffect(() => {
|
||||||
|
const oldTitle = document.title;
|
||||||
|
|
||||||
|
document.title = `${tr("Share", langCode)}🎵: ${
|
||||||
|
file.filename
|
||||||
|
} - MSW Open Music`;
|
||||||
|
|
||||||
|
// set title back
|
||||||
|
return () => {
|
||||||
|
document.title = oldTitle;
|
||||||
|
};
|
||||||
|
}, [file]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="page">
|
<div className="page">
|
||||||
<h3>{Tr("Share with others!")}</h3>
|
<h3>{Tr("Share with others!")}</h3>
|
||||||
@@ -33,7 +50,7 @@ function Share(props) {
|
|||||||
👇 {Tr("Click the filename below to enjoy music!")}
|
👇 {Tr("Click the filename below to enjoy music!")}
|
||||||
<br />
|
<br />
|
||||||
</p>
|
</p>
|
||||||
<FilesTable setPlayingFile={props.setPlayingFile} files={file} />
|
<FilesTable setPlayingFile={props.setPlayingFile} files={[file]} />
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -100,6 +100,8 @@ const LANG_zh_CN = {
|
|||||||
"filename updated": "已修改文件名",
|
"filename updated": "已修改文件名",
|
||||||
"please select a tag": "请选择一个标签",
|
"please select a tag": "请选择一个标签",
|
||||||
"files in folder": "文件夹内",
|
"files in folder": "文件夹内",
|
||||||
|
"preparing...": "转码中...",
|
||||||
|
"view source code on github": "在 Github 上查看源代码",
|
||||||
};
|
};
|
||||||
|
|
||||||
export default LANG_zh_CN;
|
export default LANG_zh_CN;
|
||||||
|
|||||||
Reference in New Issue
Block a user