ajout heimdall

This commit is contained in:
2025-01-01 11:24:01 +01:00
parent f8be42e486
commit c52f60fca9
1477 changed files with 15692 additions and 0 deletions

View File

@@ -0,0 +1,83 @@
<?php namespace App\SupportedApps\WaniKani;
class WaniKani extends \App\SupportedApps implements \App\EnhancedApps {
public $config;
//protected $login_first = true; // Uncomment if api requests need to be authed first
//protected $method = 'POST'; // Uncomment if requests to the API should be set by POST
function __construct() {
//$this->jar = new \GuzzleHttp\Cookie\CookieJar; // Uncomment if cookies need to be set
}
/**
* Try to obtain user information to test login
*/
public function login()
{
$api_token = $this->config->username;
$attrs = [
'headers' => ['Authorization' => 'Bearer '.$api_token]
];
return parent::execute($this->url('user'), $attrs, false, 'GET');
}
/**
* "Login" the user and return the username
*/
public function test()
{
$test = $this->login();
if($test->getStatusCode() === 200 && $test->getBody()) {
$wk_resp = json_decode($test->getBody());
echo "Hello ".$wk_resp->data->username;
} else {
echo "Failed";
}
}
/**
* Obtain the user summary and return the total of Reviews and Lessons
*/
public function livestats()
{
$status = 'inactive';
$now = \Carbon\Carbon::now();
$api_token = $this->config->username;
$attrs = [
'headers' => ['Authorization' => 'Bearer '.$api_token]
];
$res = parent::execute($this->url('summary'), $attrs, false, 'GET');
$details = json_decode($res->getBody());
$data = [ "lessons" => 0, "reviews" => 0 ];
foreach($details->data->lessons as $lesson)
{
$available_at = \Carbon\Carbon::createFromTimeString($lesson->available_at);
if($now >= $available_at)
{
$data["lessons"] += count($lesson->subject_ids);
}
}
foreach($details->data->reviews as $review)
{
$available_at = \Carbon\Carbon::createFromTimeString($review->available_at);
if($now >= $available_at)
{
$data["reviews"] += count($review->subject_ids);
}
}
return parent::getLiveStats($status, $data);
}
/**
* Build api url
*/
public function url($endpoint)
{
$api_url = parent::normaliseurl('https://api.wanikani.com/v2/').$endpoint;
return $api_url;
}
}

View File

@@ -0,0 +1,10 @@
{
"appid": "dc115cfaac280c4b97289484356c21428af565be",
"name": "WaniKani",
"website": "https://www.wanikani.com/",
"license": "Proprietary",
"description": "WaniKani is a Japanese radicals, kanji, and vocabulary learning web app that uses mnemonics and SRS to make kanji learning simple.",
"enhanced": true,
"tile_background": "light",
"icon": "wanikani.png"
}

View File

@@ -0,0 +1,13 @@
<h2>{{ __('app.apps.config') }} ({{ __('app.optional') }}) @include('items.enable')</h2>
<div class="items">
{!! Form::hidden('config[override_url]') !!}
{!! Form::hidden('config[password]') !!}
<div class="input">
<label>{{ __('app.apps.api_token') }}</label>
{!! Form::text('config[username]', (isset($item) ? $item->getconfig()->username : null), array('placeholder' => __('app.apps.username'), 'data-config' => 'username', 'class' => 'form-control config-item')) !!}
</div>
<div class="input">
<button style="margin-top: 32px;" class="btn test" id="test_config">Test</button>
</div>
</div>

View File

@@ -0,0 +1,10 @@
<ul class="livestats">
<li>
<span class="title">Lessons</span>
<strong>{!! $lessons !!}</strong>
</li>
<li>
<span class="title">Reviews</span>
<strong>{!! $reviews !!}</strong>
</li>
</ul>

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB