Skip to content

Commit 9cbdbe4

Browse files
author
Kevin Souza
committed
modules and routes renames, move routes and sidebar
1 parent 07e0ada commit 9cbdbe4

File tree

24 files changed

+186
-162
lines changed

24 files changed

+186
-162
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ Logs are stored in the following locations:
6161
## TODO
6262

6363
- Maybe cache users/emotes/feeds in the AppState, also maybe return them when possible in the same request instead of emitting an update event.
64-
- Add Youtube as a frontend, needs:
64+
- Add YouTube as a frontend, needs:
6565
- Fully working multi window support.
6666
- Finish reworking the UI.
6767
- Reintroduce features removed since the rework to allow for more than one window and frontend.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use tauri::{async_runtime::Mutex, AppHandle, Emitter, State};
55

66
use crate::{
77
twitch::{self, stream::LiveNow},
8-
users::Platform,
8+
user::Platform,
99
AppState,
1010
};
1111

src-tauri/src/lib.rs

Lines changed: 12 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ use tauri::{
66
Manager,
77
};
88
use tauri_plugin_deep_link::DeepLinkExt;
9-
use tauri_plugin_sql::{Migration, MigrationKind};
109

11-
mod feeds;
10+
mod feed;
11+
mod migration;
1212
mod twitch;
13-
mod users;
14-
mod utils;
13+
mod user;
14+
mod util;
1515
mod window;
1616

1717
pub struct AppState {
@@ -43,9 +43,9 @@ pub fn run() {
4343
builder = builder
4444
.plugin(
4545
tauri_plugin_sql::Builder::new()
46-
.add_migrations("sqlite:users.db", users_migrations())
47-
.add_migrations("sqlite:feeds.db", feeds_migrations())
48-
.add_migrations("sqlite:emotes.db", emotes_migrations())
46+
.add_migrations("sqlite:users.db", migration::users_migrations())
47+
.add_migrations("sqlite:feeds.db", migration::feeds_migrations())
48+
.add_migrations("sqlite:emotes.db", migration::emotes_migrations())
4949
.build(),
5050
)
5151
.plugin(tauri_plugin_http::init())
@@ -108,11 +108,11 @@ pub fn run() {
108108

109109
builder
110110
.invoke_handler(tauri::generate_handler![
111-
users::get_users,
112-
users::add_user,
113-
users::remove_user,
114-
feeds::get_feed,
115-
feeds::refresh_feed,
111+
user::get_users,
112+
user::add_user,
113+
user::remove_user,
114+
feed::get_feed,
115+
feed::refresh_feed,
116116
window::open_new_window,
117117
twitch::stream::fetch_stream_playback,
118118
twitch::proxy::proxy_stream,
@@ -121,50 +121,3 @@ pub fn run() {
121121
.run(tauri::generate_context!())
122122
.expect("while running tauri application");
123123
}
124-
125-
fn users_migrations() -> Vec<Migration> {
126-
vec![Migration {
127-
version: 1,
128-
description: "create_users_table",
129-
sql: r"
130-
CREATE TABLE IF NOT EXISTS twitch (
131-
id TEXT,
132-
username TEXT NOT NULL PRIMARY KEY,
133-
avatar BLOB
134-
);
135-
",
136-
kind: MigrationKind::Up,
137-
}]
138-
}
139-
140-
fn feeds_migrations() -> Vec<Migration> {
141-
vec![Migration {
142-
version: 1,
143-
description: "create_feeds_table",
144-
sql: r"
145-
CREATE TABLE IF NOT EXISTS twitch (
146-
username TEXT NOT NULL PRIMARY KEY,
147-
started_at TEXT
148-
);
149-
",
150-
kind: MigrationKind::Up,
151-
}]
152-
}
153-
154-
fn emotes_migrations() -> Vec<Migration> {
155-
vec![Migration {
156-
version: 1,
157-
description: "create_emotes_table",
158-
sql: r"
159-
CREATE TABLE IF NOT EXISTS twitch (
160-
username TEXT NOT NULL,
161-
name TEXT NOT NULL,
162-
url TEXT,
163-
width INTEGER,
164-
height INTEGER,
165-
PRIMARY KEY (username, name)
166-
);
167-
",
168-
kind: MigrationKind::Up,
169-
}]
170-
}

src-tauri/src/migration.rs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
use tauri_plugin_sql::{Migration, MigrationKind};
2+
3+
pub fn users_migrations() -> Vec<Migration> {
4+
vec![Migration {
5+
version: 1,
6+
description: "create_users_table",
7+
sql: r"
8+
CREATE TABLE IF NOT EXISTS twitch (
9+
id TEXT,
10+
username TEXT NOT NULL PRIMARY KEY,
11+
avatar BLOB
12+
);
13+
",
14+
kind: MigrationKind::Up,
15+
}]
16+
}
17+
18+
pub fn feeds_migrations() -> Vec<Migration> {
19+
vec![Migration {
20+
version: 1,
21+
description: "create_feeds_table",
22+
sql: r"
23+
CREATE TABLE IF NOT EXISTS twitch (
24+
username TEXT NOT NULL PRIMARY KEY,
25+
started_at TEXT
26+
);
27+
",
28+
kind: MigrationKind::Up,
29+
}]
30+
}
31+
32+
pub fn emotes_migrations() -> Vec<Migration> {
33+
vec![Migration {
34+
version: 1,
35+
description: "create_emotes_table",
36+
sql: r"
37+
CREATE TABLE IF NOT EXISTS twitch (
38+
username TEXT NOT NULL,
39+
name TEXT NOT NULL,
40+
url TEXT,
41+
width INTEGER,
42+
height INTEGER,
43+
PRIMARY KEY (username, name)
44+
);
45+
",
46+
kind: MigrationKind::Up,
47+
}]
48+
}

src-tauri/src/twitch/chat.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use tauri::{
2020
};
2121
use tokio_tungstenite::tungstenite::Message;
2222

23-
use crate::{twitch::emote, utils, AppState};
23+
use crate::{twitch::emote, util, AppState};
2424

2525
use super::emote::Emote;
2626

@@ -98,7 +98,7 @@ pub async fn join_chat(
9898
return Err(format!("Failed to send PASS: {err}"));
9999
}
100100

101-
let random_number = utils::random_number(10_000, 99_999);
101+
let random_number = util::random_number(10_000, 99_999);
102102

103103
if let Err(err) = ws_stream
104104
.send(format!("NICK justinfan{random_number}").into())

src-tauri/src/twitch/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
pub mod chat;
22
pub mod emote;
3-
pub mod stream;
43
pub mod main;
54
pub mod proxy;
6-
pub mod queries;
5+
pub mod query;
6+
pub mod stream;
77
pub mod user;

src-tauri/src/twitch/stream.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ use std::collections::HashMap;
33
use anyhow::{anyhow, Result};
44
use serde::Serialize;
55

6-
use crate::utils;
6+
use crate::util;
77

88
use super::{
99
main,
10-
queries::{GraphQLQuery, GraphQLResponse, UseLiveQuery, UseLiveResponse},
10+
query::{GraphQLQuery, GraphQLResponse, UseLiveQuery, UseLiveResponse},
1111
};
1212

1313
const USHER_API: &str = "https://usher.ttvnw.net/api/channel/hls";
@@ -107,7 +107,7 @@ pub async fn fetch_stream_playback(username: &str, backup: bool) -> Result<Strin
107107
fn playlist_url(username: &str, backup: bool, signature: &str, token: &str) -> String {
108108
let mut url = format!("{USHER_API}/{username}.m3u8");
109109

110-
let random_number = utils::random_number(1_000_000, 10_000_000);
110+
let random_number = util::random_number(1_000_000, 10_000_000);
111111

112112
if backup {
113113
url.push_str(&format!("?platform=ios&supported_codecs=h264&player=twitchweb&fast_bread=true&p={random_number}&sig={signature}&token={token}"));

src-tauri/src/twitch/user.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use log::error;
66
use super::{
77
emote::{self, Emote, TWITCH_EMOTES_CDN},
88
main,
9-
queries::{GraphQLQuery, GraphQLResponse},
9+
query::{GraphQLQuery, GraphQLResponse},
1010
};
1111

1212
pub struct TwitchUser {
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use serde::{Deserialize, Serialize};
77
use sqlx::{prelude::Type, Pool, Row, Sqlite};
88
use tauri::{async_runtime::Mutex, AppHandle, Emitter, State};
99

10-
use crate::{twitch, utils, AppState};
10+
use crate::{twitch, util, AppState};
1111

1212
#[derive(Serialize, Deserialize)]
1313
pub struct User {
@@ -20,15 +20,15 @@ pub struct User {
2020
#[derive(Serialize, Deserialize, Clone, PartialEq, Type)]
2121
pub enum Platform {
2222
#[serde(rename = "youtube")]
23-
Youtube,
23+
YouTube,
2424
#[serde(rename = "twitch")]
2525
Twitch,
2626
}
2727

2828
impl Display for Platform {
2929
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3030
match self {
31-
Platform::Youtube => write!(f, "youtube"),
31+
Platform::YouTube => write!(f, "youtube"),
3232
Platform::Twitch => write!(f, "twitch"),
3333
}
3434
}
@@ -45,7 +45,7 @@ pub async fn get_users(
4545
let users = match platform {
4646
Some(platform) => get_users_for_platform(users_db, platform).await,
4747
None => {
48-
// TODO: Merge users from all platforms when adding Youtube
48+
// TODO: Merge users from all platforms when adding YouTube
4949
get_users_for_platform(users_db, Platform::Twitch).await
5050
}
5151
};
@@ -81,7 +81,7 @@ pub async fn add_user(
8181
error!("Failed to save emotes for user '{username}': {err}");
8282
}
8383

84-
let avatar = match utils::download_image(&user.avatar).await {
84+
let avatar = match util::download_image(&user.avatar).await {
8585
Ok(bytes) => bytes,
8686
Err(err) => {
8787
return Err(format!(

0 commit comments

Comments
 (0)