Skip to content

Commit

Permalink
Feat remove non steam games (#3)
Browse files Browse the repository at this point in the history
* updated pnpm lock
* Updated pnpm version
* Added unlinking of non steam apps and cleaned up
* Updated Versions
  • Loading branch information
CEbbinghaus authored Oct 27, 2023
1 parent 62b6408 commit 05dfd2e
Show file tree
Hide file tree
Showing 13 changed files with 846 additions and 549 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:

- uses: pnpm/action-setup@v2
with:
version: 8.5.1
version: 8.9.2

- name: Download Decky CLI
run: |
Expand Down Expand Up @@ -66,7 +66,7 @@ jobs:

- uses: pnpm/action-setup@v2
with:
version: 8.5.1
version: 8.9.2

- name: Install & Build
run: |
Expand Down
2 changes: 1 addition & 1 deletion backend/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion backend/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "backend"
version = "0.9.5"
version = "0.9.6"
edition = "2021"
license = "GPL-2.0"
authors = ["Christopher-Robin Ebbinghaus <[email protected]>"]
Expand Down
90 changes: 76 additions & 14 deletions backend/src/api.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use crate::{
ds::Store,
dto::{Game, MicroSDCard},
env::PACKAGE_VERSION,
err::Error,
sdcard::{get_card_cid, is_card_inserted}, env::PACKAGE_VERSION,
sdcard::{get_card_cid, is_card_inserted},
};
use actix_web::{delete, get, post, web, HttpResponse, Responder, Result};
use serde::Deserialize;
Expand All @@ -11,9 +12,9 @@ use tokio::sync::broadcast::Sender;

pub(crate) fn config(cfg: &mut web::ServiceConfig) {
cfg.service(health)
.service(version)
.service(listen)
.service(save)
.service(version)
.service(listen)
.service(save)
.service(get_current_card)
.service(get_current_card_id)
.service(get_current_card_and_games)
Expand All @@ -23,13 +24,18 @@ pub(crate) fn config(cfg: &mut web::ServiceConfig) {
.service(list_cards)
.service(get_card)
.service(create_game)
.service(create_games)
.service(delete_game)
.service(list_games)
.service(get_game)
.service(list_games_for_card)
.service(list_cards_for_game)
.service(list_cards_with_games)
.service(create_link);
.service(create_link)
.service(create_links)
.service(delete_link)
.service(delete_links)
;
}

#[get("/version")]
Expand All @@ -44,11 +50,14 @@ pub(crate) async fn health() -> impl Responder {

#[get("/listen")]
pub(crate) async fn listen(sender: web::Data<Sender<()>>) -> Result<impl Responder> {
sender.subscribe().recv().await.map_err(|_| Error::from_str("Unable to retrieve update"))?;
sender
.subscribe()
.recv()
.await
.map_err(|_| Error::from_str("Unable to retrieve update"))?;
Ok(HttpResponse::Ok())
}


#[get("/list")]
pub(crate) async fn list_cards_with_games(datastore: web::Data<Arc<Store>>) -> impl Responder {
web::Json(datastore.list_cards_with_games())
Expand Down Expand Up @@ -77,7 +86,9 @@ pub(crate) async fn list_cards_for_game(
}

#[get("/current")]
pub(crate) async fn get_current_card_and_games(datastore: web::Data<Arc<Store>>) -> Result<impl Responder> {
pub(crate) async fn get_current_card_and_games(
datastore: web::Data<Arc<Store>>,
) -> Result<impl Responder> {
if !is_card_inserted() {
return Err(Error::from_str("No card is inserted").into());
}
Expand Down Expand Up @@ -123,7 +134,6 @@ pub(crate) async fn get_games_on_current_card(
}
}


#[post("/card/{id}")]
pub(crate) async fn create_card(
id: web::Path<String>,
Expand Down Expand Up @@ -164,7 +174,7 @@ pub(crate) async fn get_card(
Ok(web::Json(datastore.get_card(&id)?))
}

#[get("/cards")]
#[post("/cards")]
pub(crate) async fn list_cards(datastore: web::Data<Arc<Store>>) -> impl Responder {
web::Json(datastore.list_cards())
}
Expand All @@ -179,11 +189,11 @@ pub(crate) async fn create_game(
return Err(Error::from_str("uid did not match id provided").into());
}

let mut game = body.to_owned();
let mut game = body.to_owned();

if !cfg!(debug_assertions) {
game.is_steam = false;
}
if !cfg!(debug_assertions) {
game.is_steam = false;
}

datastore.add_game(id.into_inner(), game);

Expand Down Expand Up @@ -213,12 +223,36 @@ pub(crate) async fn list_games(datastore: web::Data<Arc<Store>>) -> impl Respond
web::Json(datastore.list_games())
}

#[post("/games")]
pub(crate) async fn create_games(
body: web::Json<Vec<Game>>,
datastore: web::Data<Arc<Store>>,
) -> impl Responder {
for game in body.iter() {
let mut game = game.to_owned();

if !cfg!(debug_assertions) {
game.is_steam = false;
}

datastore.add_game(game.uid.clone(), game);
}

HttpResponse::Ok()
}

#[derive(Deserialize)]
pub struct LinkBody {
card_id: String,
game_id: String,
}

#[derive(Deserialize)]
pub struct ManyLinkBody {
card_id: String,
game_ids: Vec<String>,
}

#[post("/link")]
pub(crate) async fn create_link(
body: web::Json<LinkBody>,
Expand All @@ -229,6 +263,20 @@ pub(crate) async fn create_link(
Ok(HttpResponse::Ok())
}

#[post("/linkmany")]
pub(crate) async fn create_links(
body: web::Json<ManyLinkBody>,
datastore: web::Data<Arc<Store>>,
) -> Result<impl Responder> {

let data = body.into_inner();
for game_id in data.game_ids.iter() {
datastore.link(&game_id, &data.card_id)?;
}

Ok(HttpResponse::Ok())
}

#[post("/unlink")]
pub(crate) async fn delete_link(
body: web::Json<LinkBody>,
Expand All @@ -239,6 +287,20 @@ pub(crate) async fn delete_link(
Ok(HttpResponse::Ok())
}

#[post("/unlinkmany")]
pub(crate) async fn delete_links(
body: web::Json<ManyLinkBody>,
datastore: web::Data<Arc<Store>>,
) -> Result<impl Responder> {

let data = body.into_inner();
for game_id in data.game_ids.iter() {
datastore.unlink(&game_id, &data.card_id)?;
}

Ok(HttpResponse::Ok())
}

#[post("/save")]
pub(crate) async fn save(datastore: web::Data<Arc<Store>>) -> Result<impl Responder> {
datastore.write_to_file()?;
Expand Down
2 changes: 1 addition & 1 deletion lib/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@cebbinghaus/microsdeck",
"version": "0.9.5",
"version": "0.9.6",
"description": "",
"keywords": [],
"author": "CEbbinghaus",
Expand Down
Loading

0 comments on commit 05dfd2e

Please sign in to comment.