-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Github pins, spotify recents, bug fixes (#3)
* Remove ls from dockerfile Fix issue with spotify history repeat inserting * spotify: Add recent listens route with limit param github: Add github route for pinned repos spotify: Stop from querying db every second, *clueless*
- Loading branch information
1 parent
5dfefae
commit ffbfe69
Showing
17 changed files
with
238 additions
and
22 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
use actix_web::{web, Scope}; | ||
|
||
use crate::services; | ||
|
||
pub fn github_factory() -> Scope { | ||
web::scope("/github").service(services::github::routes::github_pinned) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
pub mod factory; | ||
pub mod routes; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
use std::collections::HashMap; | ||
|
||
use actix_web::{get, http::Error, web, HttpResponse}; | ||
use envconfig::Envconfig; | ||
use gql_client::Client; | ||
use redis::{aio::ConnectionManager, AsyncCommands, RedisError}; | ||
use serde_json::json; | ||
|
||
use crate::{config::Config, structs::github::Data, ServerState}; | ||
|
||
#[get("/pinned")] | ||
async fn github_pinned( | ||
state: web::Data<ServerState>, | ||
) -> Result<HttpResponse, Error> { | ||
let query = " | ||
query GithubUserPins { | ||
user(login: \"dustinrouillard\") { | ||
pinnedItems(first: 6, types: [REPOSITORY]) { | ||
totalCount | ||
edges { | ||
node { | ||
... on Repository { | ||
owner { | ||
login | ||
} | ||
name | ||
description | ||
stargazerCount | ||
forkCount | ||
primaryLanguage { | ||
name | ||
color | ||
} | ||
pushedAt | ||
url | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
"; | ||
|
||
let valkey = &mut state.valkey.clone(); | ||
|
||
let cached = redis::cmd("GET") | ||
.arg("cache/github/pinned") | ||
.query_async::<ConnectionManager, String>(&mut valkey.cm) | ||
.await; | ||
|
||
let response: Vec<serde_json::Value> = if let Err(_) = cached { | ||
let config = Config::init_from_env().unwrap(); | ||
|
||
let mut headers = HashMap::new(); | ||
headers.insert("user-agent", "rest.dstn.to/2.0".to_string()); | ||
headers | ||
.insert("authorization", format!("token {}", config.github_pat)); | ||
|
||
let client = | ||
Client::new_with_headers("https://api.github.com/graphql", headers); | ||
|
||
let data = client.query::<Data>(query).await.unwrap(); | ||
|
||
let response = data | ||
.unwrap() | ||
.user | ||
.pinned_items | ||
.edges | ||
.iter() | ||
.map(|edge| { | ||
json!({ | ||
"owner": edge.node.owner.login, | ||
"name": edge.node.name, | ||
"description": edge.node.description, | ||
"stars": edge.node.stargazer_count, | ||
"forks": edge.node.fork_count, | ||
"language": edge.node.primary_language, | ||
"pushed_at": edge.node.pushed_at, | ||
"url": edge.node.url, | ||
}) | ||
}) | ||
.collect(); | ||
|
||
let _: Result<String, RedisError> = valkey | ||
.cm | ||
.set_ex("cache/github/pinned", json!(response).to_string(), 1800) | ||
.await; | ||
|
||
response | ||
} else { | ||
serde_json::from_str(&cached.unwrap()).unwrap() | ||
}; | ||
|
||
Ok( | ||
HttpResponse::Ok() | ||
.insert_header(("Content-Type", "application/json")) | ||
.body(json!({"repositories": response}).to_string()), | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
pub mod base; | ||
pub mod blog; | ||
pub mod github; | ||
pub mod spotify; | ||
pub mod uploads; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
use serde::{Deserialize, Serialize}; | ||
|
||
#[derive(Serialize, Deserialize, Debug)] | ||
pub struct Data { | ||
pub user: User, | ||
} | ||
|
||
#[derive(Serialize, Deserialize, Debug)] | ||
#[serde(rename_all = "camelCase")] | ||
pub struct User { | ||
pub pinned_items: PinnedItems, | ||
} | ||
|
||
#[derive(Serialize, Deserialize, Debug)] | ||
#[serde(rename_all = "camelCase")] | ||
pub struct PinnedItems { | ||
pub total_count: i64, | ||
pub edges: Vec<Edge>, | ||
} | ||
|
||
#[derive(Serialize, Deserialize, Debug)] | ||
pub struct Edge { | ||
pub node: Node, | ||
} | ||
|
||
#[derive(Serialize, Deserialize, Debug)] | ||
#[serde(rename_all = "camelCase")] | ||
pub struct Node { | ||
pub owner: Owner, | ||
pub name: String, | ||
pub description: String, | ||
pub stargazer_count: i64, | ||
pub fork_count: i64, | ||
pub primary_language: Option<PrimaryLanguage>, | ||
pub pushed_at: String, | ||
pub url: String, | ||
} | ||
|
||
#[derive(Serialize, Deserialize, Debug)] | ||
pub struct Owner { | ||
pub login: String, | ||
} | ||
|
||
#[derive(Serialize, Deserialize, Debug)] | ||
pub struct PrimaryLanguage { | ||
pub name: String, | ||
pub color: String, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
pub mod blog; | ||
pub mod github; | ||
pub mod spotify; | ||
pub mod uploads; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters