deps: migrate to api.remanso.space for everything now

This commit is contained in:
Julien Calixte
2026-03-21 10:49:39 +01:00
parent 3c736124e8
commit dfdd646eb1

View File

@@ -1,20 +1,20 @@
import { Octokit } from '@octokit/rest' import { Octokit } from "@octokit/rest"
import { addMinutes, addSeconds, isBefore } from 'date-fns' import { addMinutes, addSeconds, isBefore } from "date-fns"
import { data } from '@/data/data' import { data } from "@/data/data"
import { DataType } from '@/data/DataType.enum' import { DataType } from "@/data/DataType.enum"
import { GithubAccessToken } from '@/data/models/GithubAccessToken' import { GithubAccessToken } from "@/data/models/GithubAccessToken"
import { GithubToken } from '@/modules/user/interfaces/GithubToken' import { GithubToken } from "@/modules/user/interfaces/GithubToken"
import { GithubTokenError } from '@/modules/user/interfaces/GithubTokenError' import { GithubTokenError } from "@/modules/user/interfaces/GithubTokenError"
const AUTHENTICATION_SERVER = 'https://litenote.li212.fr' const AUTHENTICATION_SERVER = "https://api.remanso.space/auth/github"
const personalTokenId = 'token' const personalTokenId = "token"
export const signIn = async ( export const signIn = async (
code: string code: string,
): Promise<GithubToken | GithubTokenError> => { ): Promise<GithubToken | GithubTokenError> => {
const authenticationServerURL = new URL(AUTHENTICATION_SERVER) const authenticationServerURL = new URL(AUTHENTICATION_SERVER)
authenticationServerURL.searchParams.set('code', code) authenticationServerURL.searchParams.set("code", code)
const response = await fetch(authenticationServerURL.toString()) const response = await fetch(authenticationServerURL.toString())
const body = (await response.json()) as GithubToken | GithubTokenError const body = (await response.json()) as GithubToken | GithubTokenError
@@ -52,15 +52,15 @@ export const refreshToken = async () => {
if (needRefresh) { if (needRefresh) {
const authenticationServerURL = new URL(AUTHENTICATION_SERVER) const authenticationServerURL = new URL(AUTHENTICATION_SERVER)
authenticationServerURL.searchParams.set('type', 'refresh') authenticationServerURL.searchParams.set("type", "refresh")
authenticationServerURL.searchParams.set('code', accessToken.refreshToken) authenticationServerURL.searchParams.set("code", accessToken.refreshToken)
const response = await fetch(authenticationServerURL.toString()) const response = await fetch(authenticationServerURL.toString())
const githubToken = (await response.json()) as const githubToken = (await response.json()) as
| GithubToken | GithubToken
| GithubTokenError | GithubTokenError
if ('error' in githubToken) { if ("error" in githubToken) {
return null return null
} }
@@ -84,12 +84,12 @@ export const saveAccessToken = async (githubToken: GithubToken) => {
const expirationDate = addSeconds( const expirationDate = addSeconds(
new Date(), new Date(),
githubToken.expires_in githubToken.expires_in,
).toISOString() ).toISOString()
const refreshTokenExpirationDate = addSeconds( const refreshTokenExpirationDate = addSeconds(
new Date(), new Date(),
githubToken.refresh_token_expires_in githubToken.refresh_token_expires_in,
).toISOString() ).toISOString()
const accessToken: GithubAccessToken = { const accessToken: GithubAccessToken = {
@@ -102,14 +102,14 @@ export const saveAccessToken = async (githubToken: GithubToken) => {
refreshToken: githubToken.refresh_token, refreshToken: githubToken.refresh_token,
refreshTokenExpiresIn: githubToken.refresh_token_expires_in, refreshTokenExpiresIn: githubToken.refresh_token_expires_in,
refreshTokenExpirationDate, refreshTokenExpirationDate,
username: '' username: "",
} }
const octokit = new Octokit({ const octokit = new Octokit({
auth: accessToken?.token auth: accessToken?.token,
}) })
const user = await octokit.request('GET /user') const user = await octokit.request("GET /user")
accessToken.username = user.data.login accessToken.username = user.data.login
await data.add(accessToken) await data.add(accessToken)