Compare commits
7 Commits
f699fcd7f6
...
v0.0.3
| Author | SHA1 | Date | |
|---|---|---|---|
| 13adb26fba | |||
| 23ffa93615 | |||
| 23e46e5eef | |||
| c1fc8a52f4 | |||
| 6127da4626 | |||
| d208b1da91 | |||
| c329f96a76 |
12
.vscode/launch.json
vendored
12
.vscode/launch.json
vendored
@@ -4,9 +4,17 @@
|
||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
|
||||
{
|
||||
"name": "Launch Package",
|
||||
"name": "server",
|
||||
"type": "go",
|
||||
"request": "launch",
|
||||
"mode": "auto",
|
||||
"args": ["-document-root", "${workspaceFolder}/env"],
|
||||
"console": "integratedTerminal",
|
||||
"program": "${workspaceFolder}/cmd/server"
|
||||
},
|
||||
{
|
||||
"name": "cli",
|
||||
"type": "go",
|
||||
"request": "launch",
|
||||
"mode": "auto",
|
||||
|
||||
7
LICENSE
Normal file
7
LICENSE
Normal file
@@ -0,0 +1,7 @@
|
||||
Copyright 2025 Aurélie DELHAIE
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
56
README.md
Normal file
56
README.md
Normal file
@@ -0,0 +1,56 @@
|
||||
# CloudSave
|
||||
|
||||
The software is still in alpha.
|
||||
|
||||
A client/server that allows unsynchronized games (such as emulators, old games, etc.) to be kept up to date on multiple computers.
|
||||
|
||||
## Build
|
||||
|
||||
You need go1.24
|
||||
|
||||
After downloading the go toolchain, just run the script `./build.sh`
|
||||
|
||||
## Usage
|
||||
|
||||
### Server
|
||||
|
||||
The server needs an empty directory. After creating this directory, you need to make a file that contains your credential. The format is "username:password". The server only understand bcrypt password hash for now.
|
||||
|
||||
e.g.:
|
||||
```
|
||||
test:$2y$10$uULsuyROe3LVdTzFoBH7HO0zhvyKp6CX2FDNl7quXMFYqzitU0kc.
|
||||
```
|
||||
|
||||
The default path to this directory is `/var/lib/cloudsave`, this can be changed with the `-document-root` argument
|
||||
|
||||
### Client
|
||||
|
||||
#### Register a game
|
||||
|
||||
You can register a game with the verb `add`
|
||||
```bash
|
||||
cloudsave add /home/user/gamedata
|
||||
```
|
||||
|
||||
You can also change the name of the registration and add a remote
|
||||
```bash
|
||||
cloudsave add -name "My Game" -remote "http://localhost:8080" /home/user/gamedata
|
||||
```
|
||||
|
||||
#### Make an archive of the current state
|
||||
|
||||
This is a command line tool, it cannot auto detect changes.
|
||||
Run this command to start the scan, if needed, the tool will create a new archive
|
||||
|
||||
```bash
|
||||
cloudsave scan
|
||||
```
|
||||
#### Send everythings on the server
|
||||
|
||||
This will pull and push data to the server.
|
||||
|
||||
Note: If multiple computers are pushing to this server, a conflict may be generated. If so, the tool will ask for the version to keep
|
||||
|
||||
```bash
|
||||
cloudsave sync
|
||||
```
|
||||
2
build.sh
2
build.sh
@@ -70,7 +70,7 @@ for platform in "${platforms[@]}"; do
|
||||
|
||||
if [ "$MAKE_PACKAGE" == "true" ]; then
|
||||
CGO_ENABLED=0 GOOS=${platform_split[0]} GOARCH=${platform_split[1]} go build -o build/cloudsave_web$EXT -a ./cmd/web
|
||||
tar -czf build/server_${platform_split[0]}_${platform_split[1]}.tar.gz build/cloudsave_web$EXT
|
||||
tar -czf build/web_${platform_split[0]}_${platform_split[1]}.tar.gz build/cloudsave_web$EXT
|
||||
rm build/cloudsave_web$EXT
|
||||
else
|
||||
CGO_ENABLED=0 GOOS=${platform_split[0]} GOARCH=${platform_split[1]} go build -o build/cloudsave_web_${platform_split[0]}_${platform_split[1]}$EXT -a ./cmd/web
|
||||
|
||||
@@ -3,12 +3,9 @@ package api
|
||||
import (
|
||||
"cloudsave/cmd/server/data"
|
||||
"cloudsave/pkg/repository"
|
||||
"crypto/md5"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"log/slog"
|
||||
"net/http"
|
||||
"os"
|
||||
@@ -343,41 +340,19 @@ func (s HTTPServer) histExists(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
func (s HTTPServer) hash(w http.ResponseWriter, r *http.Request) {
|
||||
id := chi.URLParam(r, "id")
|
||||
path := filepath.Clean(filepath.Join(s.documentRoot, "data", id))
|
||||
|
||||
sdir, err := os.Stat(path)
|
||||
sum, err := data.Hash(id, s.documentRoot)
|
||||
if err != nil {
|
||||
notFound("id not found", w, r)
|
||||
return
|
||||
}
|
||||
|
||||
if !sdir.IsDir() {
|
||||
notFound("id not found", w, r)
|
||||
return
|
||||
}
|
||||
|
||||
path = filepath.Join(path, "data.tar.gz")
|
||||
|
||||
f, err := os.OpenFile(path, os.O_RDONLY, 0)
|
||||
if err != nil {
|
||||
notFound("id not found", w, r)
|
||||
return
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
// Create MD5 hasher
|
||||
hasher := md5.New()
|
||||
|
||||
// Copy file content into hasher
|
||||
if _, err := io.Copy(hasher, f); err != nil {
|
||||
fmt.Fprintln(os.Stderr, "error: an error occured while reading data:", err)
|
||||
if errors.Is(err, data.ErrNotExists) {
|
||||
notFound("id not found", w, r)
|
||||
return
|
||||
}
|
||||
fmt.Fprintln(os.Stderr, "error: an error occured while calculating the hash:", err)
|
||||
internalServerError(w, r)
|
||||
return
|
||||
}
|
||||
|
||||
// Get checksum result
|
||||
sum := hasher.Sum(nil)
|
||||
ok(hex.EncodeToString(sum), w, r)
|
||||
ok(sum, w, r)
|
||||
}
|
||||
|
||||
func (s HTTPServer) metadata(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
@@ -23,6 +23,7 @@ type (
|
||||
|
||||
var (
|
||||
ErrBackupNotExists error = errors.New("backup not found")
|
||||
ErrNotExists error = errors.New("not found")
|
||||
|
||||
// singleton
|
||||
hashCacheMu sync.RWMutex
|
||||
@@ -175,6 +176,9 @@ func Hash(gameID, documentRoot string) (string, error) {
|
||||
|
||||
sdir, err := os.Stat(path)
|
||||
if err != nil {
|
||||
if errors.Is(err, os.ErrNotExist) {
|
||||
return "", ErrNotExists
|
||||
}
|
||||
return "", err
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user