mirror of
https://github.com/ArthurDanjou/artdanj-api.git
synced 2026-01-27 10:00:27 +01:00
Fix 403
This commit is contained in:
@@ -1,16 +1,18 @@
|
|||||||
import { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'
|
import { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'
|
||||||
import {getTotalStats, getWeeklyStats, getMonthlyStats, getOtherStats} from 'App/Helpers/StatsHelper'
|
import {getTotalStats, getWeeklyStats, getMonthlyStats, getOtherStats, getDailyStats} from 'App/Helpers/StatsHelper'
|
||||||
import DockerBuild from "App/Models/DockerBuild";
|
import DockerBuild from "App/Models/DockerBuild"
|
||||||
import DockerCommand from "App/Models/DockerCommand";
|
import DockerCommand from "App/Models/DockerCommand"
|
||||||
|
|
||||||
export default class StatsController {
|
export default class StatsController {
|
||||||
|
|
||||||
public async get ({response}: HttpContextContract) {
|
public async get ({response}: HttpContextContract) {
|
||||||
const weekly = await getWeeklyStats();
|
const daily = await getDailyStats()
|
||||||
const monthly = await getMonthlyStats();
|
const weekly = await getWeeklyStats()
|
||||||
const total = await getTotalStats();
|
const monthly = await getMonthlyStats()
|
||||||
const other = await getOtherStats();
|
const total = await getTotalStats()
|
||||||
|
const other = await getOtherStats()
|
||||||
return response.status(200).send({
|
return response.status(200).send({
|
||||||
|
daily: daily,
|
||||||
weekly: weekly,
|
weekly: weekly,
|
||||||
monthly: monthly,
|
monthly: monthly,
|
||||||
total: total,
|
total: total,
|
||||||
|
|||||||
@@ -2,10 +2,22 @@ import DockerCommand from "App/Models/DockerCommand";
|
|||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import DockerBuild from "App/Models/DockerBuild";
|
import DockerBuild from "App/Models/DockerBuild";
|
||||||
|
|
||||||
|
async function getDailyStats() {
|
||||||
|
const commands = await DockerCommand.query().where('created_at', '>', new Date().getTime())
|
||||||
|
const {data} = await axios.get('https://wakatime.com/api/v1/users/arthurdanjou/stats/last_7_days')
|
||||||
|
const builds = await DockerBuild.query().where('created_at', '>', new Date().getTime())
|
||||||
|
|
||||||
|
return {
|
||||||
|
development_hours: data.data[0].grand_total.total_seconds / 60 / 60,
|
||||||
|
docker_commands_run: commands.length,
|
||||||
|
docker_build_count: builds.length,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function getWeeklyStats() {
|
async function getWeeklyStats() {
|
||||||
const commands = await DockerCommand.query().where('created_at', '>', new Date().getTime() - 1000 * 60 * 60 * 24 * 7)
|
const commands = await DockerCommand.query().where('created_at', '>', new Date().getTime() - 1000 * 60 * 60 * 24 * 7)
|
||||||
const {data} = await axios.get('https://wakatime.com/api/v1/users/arthurdanjou/stats/last_7_days')
|
const {data} = await axios.get('https://wakatime.com/api/v1/users/arthurdanjou/stats/last_7_days')
|
||||||
const builds = await DockerBuild.query().where('created_at', '>', new Date().getMonth() - 1)
|
const builds = await DockerBuild.query().where('created_at', '>', new Date().getTime() - 1000 * 60 * 60 * 24 * 7)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
development_hours: data.data.total_seconds / 60 / 60,
|
development_hours: data.data.total_seconds / 60 / 60,
|
||||||
@@ -56,4 +68,4 @@ async function getOtherStats() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export {getMonthlyStats, getTotalStats, getWeeklyStats, getOtherStats}
|
export {getMonthlyStats, getTotalStats, getWeeklyStats, getOtherStats, getDailyStats}
|
||||||
|
|||||||
17
app/Helpers/WakatimeLogger.ts
Normal file
17
app/Helpers/WakatimeLogger.ts
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
import axios from "axios";
|
||||||
|
import Env from '@ioc:Adonis/Core/Env'
|
||||||
|
|
||||||
|
async function login() {
|
||||||
|
await axios.post("https://wakatime.com/oauth/token",
|
||||||
|
{
|
||||||
|
client_id: Env.get('WAKATIME_USERNAME'),
|
||||||
|
client_secret: Env.get('WAKATIME_PASSWORD')
|
||||||
|
},
|
||||||
|
{
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/x-www-form-urlencoded'
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export { login }
|
||||||
@@ -35,6 +35,9 @@ Tasks: kernel : setTimeout or cron
|
|||||||
Deezer songs: 1min
|
Deezer songs: 1min
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
Route.get('/source', async ({response}: HttpContextContract) => {
|
||||||
|
return response.redirect('https://github.com/arthurdanjou/artapi')
|
||||||
|
})
|
||||||
Route.get('/location', 'LocationsController.get')
|
Route.get('/location', 'LocationsController.get')
|
||||||
Route.get('/location/history', 'LocationsController.history')
|
Route.get('/location/history', 'LocationsController.history')
|
||||||
Route.get('/stats', 'StatsController.get')
|
Route.get('/stats', 'StatsController.get')
|
||||||
|
|||||||
Reference in New Issue
Block a user