Skip to content

Commit 2afa138

Browse files
committed
Release: v1.0.6
1 parent 91e3234 commit 2afa138

File tree

13 files changed

+222
-24
lines changed

13 files changed

+222
-24
lines changed

.github/workflows/releases.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ jobs:
2323
args: ''
2424

2525
runs-on: ${{ matrix.settings.platform }}
26+
env:
27+
DB_USER: ${{ secrets.DB_USER }}
28+
DB_PASSWORD: ${{ secrets.DB_PASSWORD }}
2629
steps:
2730
- uses: actions/checkout@v4
2831

@@ -71,6 +74,43 @@ jobs:
7174
# If you don't have `beforeBuildCommand` configured you may want to build your frontend here too.
7275
run: pnpm install # change this to npm or pnpm depending on which one you use.
7376

77+
- name: replace .env file (linux only)
78+
if: matrix.settings.platform == 'ubuntu-22.04'
79+
run: |
80+
if [[ -n "${{ secrets.DB_USER }}" ]] && [[ -n "${{ secrets.DB_PASSWORD }}" ]]; then
81+
sed -i 's/DATABASE_URL=mysql:\/\/root:@127.0.0.1:3306\/libraryroom/DATABASE_URL=mysql:\/\/${{ secrets.DB_USER }}:${{ secrets.DB_PASSWORD }}@127.0.0.1:3306\/libraryroom/g' "src-tauri/.env"
82+
elif [[ -n "${{ secrets.DB_USER }}" ]]; then
83+
sed -i 's/DATABASE_URL=mysql:\/\/root:@127.0.0.1:3306\/libraryroom/DATABASE_URL=mysql:\/\/${{ secrets.DB_USER }}:@127.0.0.1:3306\/libraryroom/g' "src-tauri/.env"
84+
elif [[ -n "${{ secrets.DB_PASSWORD }}" ]]; then
85+
sed -i 's/DATABASE_URL=mysql:\/\/root:@127.0.0.1:3306\/libraryroom/DATABASE_URL=mysql:\/\/root:${{ secrets.DB_PASSWORD }}@127.0.0.1:3306\/libraryroom/g' "src-tauri/.env"
86+
fi
87+
88+
- name: replace .env file (macos only)
89+
if: matrix.settings.platform != 'ubuntu-22.04' && matrix.settings.platform != 'windows-latest'
90+
run: |
91+
if [[ -n "${{ secrets.DB_USER }}" ]] && [[ -n "${{ secrets.DB_PASSWORD }}" ]]; then
92+
sed 's/DATABASE_URL=mysql:\/\/root:@127.0.0.1:3306\/libraryroom/DATABASE_URL=mysql:\/\/${{ secrets.DB_USER }}:${{ secrets.DB_PASSWORD }}@127.0.0.1:3306\/libraryroom/g' "src-tauri/.env"
93+
elif [[ -n "${{ secrets.DB_USER }}" ]]; then
94+
sed 's/DATABASE_URL=mysql:\/\/root:@127.0.0.1:3306\/libraryroom/DATABASE_URL=mysql:\/\/${{ secrets.DB_USER }}:@127.0.0.1:3306\/libraryroom/g' "src-tauri/.env"
95+
elif [[ -n "${{ secrets.DB_PASSWORD }}" ]]; then
96+
sed 's/DATABASE_URL=mysql:\/\/root:@127.0.0.1:3306\/libraryroom/DATABASE_URL=mysql:\/\/root:${{ secrets.DB_PASSWORD }}@127.0.0.1:3306\/libraryroom/g' "src-tauri/.env"
97+
fi
98+
99+
- name: replace .env file (windows only)
100+
if: matrix.settings.platform == 'windows-latest'
101+
run: |
102+
$envContent = Get-Content src-tauri/.env
103+
if ($env:DB_USER) {
104+
if ($env:DB_PASSWORD) {
105+
$envContent = $envContent -replace 'DATABASE_URL=mysql://root:@127.0.0.1:3306/libraryroom', "DATABASE_URL=mysql://$env:DB_USER:$env:[email protected]:3306/libraryroom"
106+
} else {
107+
$envContent = $envContent -replace 'DATABASE_URL=mysql://root:@127.0.0.1:3306/libraryroom', "DATABASE_URL=mysql://$env:DB_USER:@127.0.0.1:3306/libraryroom"
108+
}
109+
} elseif ($env:DB_PASSWORD) {
110+
$envContent = $envContent -replace 'DATABASE_URL=mysql://root:@127.0.0.1:3306/libraryroom', "DATABASE_URL=mysql://root:$env:[email protected]:3306/libraryroom"
111+
}
112+
$envContent | Set-Content src-tauri/.env
113+
74114
- uses: tauri-apps/tauri-action@v0
75115
env:
76116
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "libraryroombookingsystem",
33
"private": true,
4-
"version": "1.0.5",
4+
"version": "1.0.6",
55
"type": "module",
66
"scripts": {
77
"dev": "vite",

src-tauri/Cargo.lock

Lines changed: 106 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src-tauri/Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "LibraryRoomBookingSystem"
3-
version = "1.0.5"
3+
version = "1.0.6"
44
description = "A Library Room Booking System built with Tauri and Rust"
55
authors = ["Lim Shi Song [email protected]"]
66
edition = "2021"
@@ -9,6 +9,7 @@ edition = "2021"
99

1010
[build-dependencies]
1111
tauri-build = { version = "1", features = [] }
12+
dotenvy = "0.15.7"
1213

1314
[dependencies]
1415
tauri = { version = "1", features = ["shell-open"] }
@@ -17,6 +18,7 @@ jsonwebtoken = "9"
1718
serde_json = "1"
1819
dotenvy = "0.15.7"
1920
chrono = "0.4.38"
21+
envcrypt = "0.5.0"
2022

2123
[dependencies.tauri-plugin-sql]
2224
git = "https://github.com/tauri-apps/plugins-workspace"

src-tauri/build.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
11
fn main() {
2-
tauri_build::build()
2+
println!("cargo:rerun-if-changed=.env");
3+
4+
for item in dotenvy::dotenv_iter().unwrap() {
5+
let (key, value) = item.unwrap();
6+
println!("cargo:rustc-env={key}={value}");
7+
}
8+
tauri_build::build();
39
}

src-tauri/src/main.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
mod models;
55

6+
use envcrypt::envc;
67
use jsonwebtoken::{
78
decode, encode, get_current_timestamp, Algorithm, DecodingKey, EncodingKey, Header, Validation,
89
};
@@ -60,10 +61,15 @@ fn get_env(key: &str) -> Result<String, String> {
6061
}
6162
}
6263

64+
#[tauri::command]
65+
fn get_db_url() -> Result<String, String> {
66+
Ok(envc!("DATABASE_URL").to_string())
67+
}
68+
6369
fn main() {
6470
tauri::Builder::default()
6571
.plugin(tauri_plugin_sql::Builder::default().build())
66-
.invoke_handler(tauri::generate_handler![login, get_env, check_auth])
72+
.invoke_handler(tauri::generate_handler![login, get_env, check_auth, get_db_url])
6773
.run(tauri::generate_context!())
6874
.expect("error while running tauri application");
6975
}

src-tauri/tauri.conf.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
},
88
"package": {
99
"productName": "LibraryRoomBookingSystem",
10-
"version": "1.0.5"
10+
"version": "1.0.6"
1111
},
1212
"tauri": {
1313
"allowlist": {
@@ -31,9 +31,6 @@
3131
"active": true,
3232
"targets": "all",
3333
"identifier": "com.library-room-booking-system.app",
34-
"resources": [
35-
".env"
36-
],
3734
"icon": [
3835
"icons/32x32.png",
3936
"icons/128x128.png",

src/lib/auth.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { invoke } from "@tauri-apps/api/tauri";
22
import { goto } from "$app/navigation";
33
import { hashPassword, verify } from "./crypto/hashing";
4-
import Cookies from "js-cookie";
54
import { getDB } from "./db";
65
import { getUserByEmail } from "./models/user";
6+
import { setItem } from "./helper";
77

88
export async function login(email, password, usertype, link) {
99
let user = await getUserByEmail(email, usertype);
@@ -17,9 +17,8 @@ export async function login(email, password, usertype, link) {
1717
let token = await invoke("login", {
1818
user,
1919
});
20-
21-
let expiredDate = new Date(token.exp * 1000);
22-
Cookies.set("token", token.token, { expires: expiredDate });
20+
console.log(token);
21+
setItem("token", token.token, token.exp);
2322
goto(link);
2423
};
2524

src/lib/db.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ import Database from "tauri-plugin-sql-api";
22
import { invoke } from "@tauri-apps/api/tauri";
33

44
export async function getDB() {
5-
let dbUrl = await invoke("get_env", { key: "DATABASE_URL" });
5+
let dbUrl = await invoke("get_db_url");
66
return await Database.load(dbUrl);
77
}

src/lib/helper.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,4 +178,37 @@ export function isNoRoomNumber(roomName) {
178178
return getRoomType().find(room => room.name === roomName).price === 0;
179179
}
180180
return false;
181+
}
182+
183+
/**
184+
* @param {String} key
185+
* @param {String} value
186+
* @param {Number} maxAge
187+
*/
188+
export function setItem(key, value, maxAge = 30 * 30 * 60) {
189+
maxAge = maxAge * 1000;
190+
let result = {
191+
data: value
192+
}
193+
194+
if (maxAge) {
195+
result.expireTime = maxAge;
196+
}
197+
window.localStorage.setItem(key, JSON.stringify(result));
198+
}
199+
200+
/**
201+
* @param {String} key
202+
* @returns
203+
*/
204+
export function getItem(key) {
205+
let result = JSON.parse(window.localStorage.getItem(key));
206+
if (result) {
207+
if (result.expireTime <= Date.now()) {
208+
window.localStorage.removeItem(key);
209+
return null;
210+
}
211+
return result.data;
212+
}
213+
return null;
181214
}

0 commit comments

Comments
 (0)