mirror of
https://github.com/ArthurDanjou/artdanj-api.git
synced 2026-01-26 17:40:27 +01:00
Working on new version of website
Signed-off-by: Arthur DANJOU <arthurdanjou@outlook.fr>
This commit is contained in:
@@ -1,55 +0,0 @@
|
||||
import Redis from "@ioc:Adonis/Addons/Redis";
|
||||
import axios from 'axios'
|
||||
import Env from "@ioc:Adonis/Core/Env";
|
||||
|
||||
export async function UpdateGitHubReadme(): Promise<void> {
|
||||
const sleeping = await Redis.get('states:sleeping')
|
||||
const learning = await Redis.get('states:learning')
|
||||
const developing = await Redis.get('states:developing')
|
||||
const listening_music = await Redis.get('states:listening')
|
||||
|
||||
const infos_table = `| Informations | State |
|
||||
| ---------------------------: | ------: |
|
||||
| :musical_note: Music Playing | **${getStatus(listening_music)}** |
|
||||
| :bed: Sleeping | **${getStatus(sleeping)}** |
|
||||
| :computer: Developing | **${getStatus(developing)}** |
|
||||
| :books: Learning | **${getStatus(learning)}** |`
|
||||
|
||||
let change = true;
|
||||
|
||||
const {data: read_me} = await axios.get('https://api.github.com/repos/arthurdanjou/arthurdanjou/readme', {
|
||||
headers: {
|
||||
authorization: `Bearer ${Env.get('GITHUB_TOKEN')}`
|
||||
},
|
||||
})
|
||||
|
||||
const content = Buffer.from(read_me.content, 'base64').toString()
|
||||
|
||||
const infos_table_check = '| Informations' + content.split('| Informations')[1]
|
||||
if (!infos_table_check) change = true
|
||||
const old_infos_table = infos_table_check.split('###### Curious')[0]
|
||||
if (!old_infos_table) change = true
|
||||
|
||||
if (!change) return
|
||||
|
||||
await axios.put('https://api.github.com/repos/ArthurDanjou/ArthurDanjou/contents/README.md',
|
||||
{
|
||||
message: 'Updating recent statistics & informations',
|
||||
content: Buffer.from(content.replace(old_infos_table, infos_table + '\n\n'), 'utf8').toString('base64'),
|
||||
sha: read_me.sha,
|
||||
author: {
|
||||
name: 'api.arthurdanjou.fr - API Automation',
|
||||
email: 'me@arthurdanjou.fr'
|
||||
}
|
||||
}, {
|
||||
headers: {
|
||||
authorization: `Bearer ${Env.get('GITHUB_TOKEN')}`
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
function getStatus(state): string {
|
||||
if (state === null) return "No"
|
||||
return state === "true" ? "Yes" : "No"
|
||||
}
|
||||
9
app/Tasks/getTranslation.ts
Normal file
9
app/Tasks/getTranslation.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
import Translation from "App/Models/Translation";
|
||||
|
||||
export default async function getTranslation(code: string): Promise<Translation> {
|
||||
let translation = await Translation.findBy('code', code)
|
||||
if (!translation) {
|
||||
translation = await Translation.create({code: code})
|
||||
}
|
||||
return translation
|
||||
}
|
||||
Reference in New Issue
Block a user