incomplete
This commit is contained in:
parent
7fbb71a4c1
commit
fdcba863c2
@ -20,6 +20,10 @@ indent_size = 4
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
|
||||
[{*.cr,shard.yml}]
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
|
||||
[humans.txt]
|
||||
indent_style = tab
|
||||
indent_size = 2
|
||||
|
@ -3,3 +3,4 @@ app/assets/css/bootstrap*
|
||||
app/assets/js/bootstrap*
|
||||
package.json
|
||||
package-lock.json
|
||||
server/
|
||||
|
@ -1,8 +1,12 @@
|
||||
import { routes } from './routes.js';
|
||||
|
||||
let DEBUG = false;
|
||||
let DEBUG = true;
|
||||
window.DEBUG = DEBUG;
|
||||
|
||||
let SERVER_URL;
|
||||
if (DEBUG) SERVER_HOST = 'localhost';
|
||||
else SERVER_HOST = 'a2s.su';
|
||||
|
||||
/* main */
|
||||
window.onload = function () {
|
||||
let app = document.documentElement;
|
||||
@ -69,3 +73,21 @@ const location_handler = async () => {
|
||||
document.querySelector('#autorun').innerHTML = '';
|
||||
}
|
||||
};
|
||||
|
||||
function get_from_api(callback, api_method = '', params = {}) {
|
||||
respone = '';
|
||||
|
||||
if (api_method == '') {
|
||||
console.log('wrong method');
|
||||
} else {
|
||||
fetch(`http://${SERVER_HOST}:3000/api/v1.0/${api_method}`)
|
||||
.then((response) => {
|
||||
return response.json();
|
||||
})
|
||||
.then((data) => {
|
||||
callback(data);
|
||||
})
|
||||
.catch((err) => console.warn('Something went wrong.', err));
|
||||
}
|
||||
}
|
||||
window.get_from_api = get_from_api;
|
||||
|
3
public/js/rev2.js
Normal file
3
public/js/rev2.js
Normal file
@ -0,0 +1,3 @@
|
||||
export function update_rev2(data) {
|
||||
let time_remaining = document.getElementById('rev2_time_remaining')
|
||||
}
|
@ -14,26 +14,31 @@
|
||||
<span class="text-nowrap">«Вторжение огромных тварей»</span>
|
||||
</h3>
|
||||
|
||||
<img
|
||||
class="img-fluid shadow rounded m-3"
|
||||
src="/content/images/2023/resident_evil_revelations_2_wallpaper_by_brendabirkin.jpg"
|
||||
/>
|
||||
<p class="text-center text-muted">
|
||||
Изображение:
|
||||
<a
|
||||
class="text-reset"
|
||||
href="https://www.deviantart.com/brendabirkin/art/Resident-Evil-Revelations-2-Wallpaper-521674087"
|
||||
target="_blank"
|
||||
>
|
||||
Resident Evil Revelations 2 — Wallpaper by BrendaBirkin
|
||||
</a>
|
||||
</p>
|
||||
<div class="d-none">
|
||||
<img
|
||||
class="img-fluid shadow rounded m-3"
|
||||
src="/content/images/2023/resident_evil_revelations_2_wallpaper_by_brendabirkin.jpg"
|
||||
/>
|
||||
<p class="text-center text-muted">
|
||||
Изображение:
|
||||
<a
|
||||
class="text-reset"
|
||||
href="https://www.deviantart.com/brendabirkin/art/Resident-Evil-Revelations-2-Wallpaper-521674087"
|
||||
target="_blank"
|
||||
>
|
||||
Resident Evil Revelations 2 — Wallpaper by BrendaBirkin
|
||||
</a>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div class="card mb-3">
|
||||
<div class="card-header">
|
||||
<div class="d-flex justify-content-between">
|
||||
<div class="d-flex justify-content-between placeholder-glow">
|
||||
<span class="fw-bold">Invasion of the Huge Creatures No. 101</span>
|
||||
<span>Осталось времени: 656:49</span>
|
||||
<span
|
||||
id="rev2_time_remaining"
|
||||
class="placeholder col-1 rounded"
|
||||
></span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
@ -56,31 +61,34 @@
|
||||
/>
|
||||
</svg>
|
||||
</h5>
|
||||
<p class="my-1 fw-bold d-flex justify-content-between">
|
||||
<span>Aello</span>
|
||||
<span class="text-danger">[100 00 000 / 999 999 999]</span>
|
||||
</p>
|
||||
<div
|
||||
class="progress"
|
||||
role="progressbar"
|
||||
aria-valuenow="21"
|
||||
aria-valuemin="0"
|
||||
aria-valuemax="100"
|
||||
>
|
||||
<div class="progress-bar bg-danger" style="width: 21%">21%</div>
|
||||
</div>
|
||||
<p class="my-1 fw-bold d-flex justify-content-between">
|
||||
<span>Ocypete</span>
|
||||
<span class="text-danger">[100 00 000 / 999 999 999]</span>
|
||||
</p>
|
||||
<div
|
||||
class="progress"
|
||||
role="progressbar"
|
||||
aria-valuenow="91"
|
||||
aria-valuemin="0"
|
||||
aria-valuemax="100"
|
||||
>
|
||||
<div class="progress-bar bg-danger" style="width: 91%">91%</div>
|
||||
|
||||
<div id="rev2_emenies">
|
||||
<p class="my-1 fw-bold d-flex justify-content-between">
|
||||
<span>Aello</span>
|
||||
<span class="text-danger">[? / ?]</span>
|
||||
</p>
|
||||
<div
|
||||
class="progress"
|
||||
role="progressbar"
|
||||
aria-valuenow="21"
|
||||
aria-valuemin="0"
|
||||
aria-valuemax="100"
|
||||
>
|
||||
<div class="progress-bar bg-danger" style="width: 21%">21%</div>
|
||||
</div>
|
||||
<p class="my-1 fw-bold d-flex justify-content-between">
|
||||
<span>Ocypete</span>
|
||||
<span class="text-danger">[? / ?]</span>
|
||||
</p>
|
||||
<div
|
||||
class="progress"
|
||||
role="progressbar"
|
||||
aria-valuenow="91"
|
||||
aria-valuemin="0"
|
||||
aria-valuemax="100"
|
||||
>
|
||||
<div class="progress-bar bg-danger" style="width: 91%">91%</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card-footer text-body-secondary">
|
||||
@ -119,4 +127,19 @@
|
||||
>
|
||||
</p>
|
||||
|
||||
<script type="module"></script>
|
||||
<script type="module">
|
||||
import { update_rev2 } from './js/rev2.js';
|
||||
|
||||
function autorun() {
|
||||
if (true) {
|
||||
get_from_api((data) => {update_rev2(data);}, 'rev2_monsters')
|
||||
setInterval(autorun, 120_000); // 2 minutes
|
||||
} else {
|
||||
console.log(
|
||||
'INFO! Включена отладка, данные не загружается!\n' +
|
||||
'Файл rer2.html',
|
||||
);
|
||||
}
|
||||
}
|
||||
autorun();
|
||||
</script>
|
||||
|
3
server/.gitignore
vendored
Normal file
3
server/.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
bin/
|
||||
lib/
|
||||
cache/
|
0
server/README.md
Normal file
0
server/README.md
Normal file
22
server/shard.lock
Normal file
22
server/shard.lock
Normal file
@ -0,0 +1,22 @@
|
||||
version: 2.0
|
||||
shards:
|
||||
backtracer:
|
||||
git: https://github.com/sija/backtracer.cr.git
|
||||
version: 1.2.2
|
||||
|
||||
exception_page:
|
||||
git: https://github.com/crystal-loot/exception_page.git
|
||||
version: 0.3.1
|
||||
|
||||
kemal:
|
||||
git: https://github.com/kemalcr/kemal.git
|
||||
version: 1.4.0
|
||||
|
||||
lexbor:
|
||||
git: https://github.com/kostya/lexbor.git
|
||||
version: 3.1.2
|
||||
|
||||
radix:
|
||||
git: https://github.com/luislavena/radix.git
|
||||
version: 0.4.1
|
||||
|
24
server/shard.yml
Normal file
24
server/shard.yml
Normal file
@ -0,0 +1,24 @@
|
||||
name: api_server
|
||||
version: 0.1.0
|
||||
|
||||
authors:
|
||||
- Alexander Popov <iiiypuk@fastmail.fm>
|
||||
|
||||
# description: |
|
||||
# Short description of server
|
||||
|
||||
targets:
|
||||
api:
|
||||
main: src/api.cr
|
||||
|
||||
dependencies:
|
||||
kemal:
|
||||
github: kemalcr/kemal
|
||||
lexbor:
|
||||
github: kostya/lexbor
|
||||
|
||||
# development_dependencies:
|
||||
# webmock:
|
||||
# github: manastech/webmock.cr
|
||||
|
||||
license: WTFPL
|
11
server/src/api.cr
Normal file
11
server/src/api.cr
Normal file
@ -0,0 +1,11 @@
|
||||
require "kemal"
|
||||
require "./modules/*"
|
||||
|
||||
APP = {version: "1.0.0"}
|
||||
|
||||
get "/" do
|
||||
render "#{__DIR__}/layouts/index.ecr"
|
||||
end
|
||||
|
||||
Kemal.config.env = "development"
|
||||
Kemal.run
|
13
server/src/layouts/index.ecr
Normal file
13
server/src/layouts/index.ecr
Normal file
@ -0,0 +1,13 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>api</title>
|
||||
</head>
|
||||
<body>
|
||||
<main>
|
||||
<p>:-p</p>
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
16
server/src/modules/_api.cr
Normal file
16
server/src/modules/_api.cr
Normal file
@ -0,0 +1,16 @@
|
||||
require "json"
|
||||
|
||||
get "/info" do |env|
|
||||
version = APP["version"]
|
||||
|
||||
if env.params.query["json"]?
|
||||
env.response.content_type = "application/json"
|
||||
|
||||
data = {version: version}.to_json
|
||||
data
|
||||
else
|
||||
env.response.content_type = "text/plain"
|
||||
|
||||
"Vesrion: #{version}"
|
||||
end
|
||||
end
|
54
server/src/modules/rev2.cr
Normal file
54
server/src/modules/rev2.cr
Normal file
@ -0,0 +1,54 @@
|
||||
require "http/client"
|
||||
require "json"
|
||||
|
||||
require "lexbor"
|
||||
|
||||
# ...
|
||||
#
|
||||
# Output:
|
||||
# ```
|
||||
# ...
|
||||
# ```
|
||||
get "/api/v1.0/rev2_monsters" do |env|
|
||||
url = "https://game.capcom.com/residentevil/en/onlineevent-4_1108.html"
|
||||
|
||||
cache_time = File.read("./cache/rev2/time.txt").to_i
|
||||
|
||||
timestamp = Time.local.to_unix
|
||||
|
||||
if timestamp > cache_time + 3600 # 1 hour
|
||||
response = HTTP::Client.get url
|
||||
|
||||
time_remaining = ""
|
||||
enemies = [] of String
|
||||
|
||||
Lexbor::Parser.new(response.body).nodes(:dl).each do |node|
|
||||
if node["class"]?
|
||||
if node["class"] == "timer big status_1 hard windows"
|
||||
time_remaining = node.inner_text.split[2]
|
||||
end
|
||||
|
||||
if node["class"] == "status hard windows status_1"
|
||||
enemies = node.inner_text.split
|
||||
enemies.delete_at(0, 2)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
enemies.each_with_index do |ememy, i|
|
||||
hp = /\d+%/.match(ememy)
|
||||
enemies[i] = enemies[i].gsub(/\d+%/, " \\0")
|
||||
end
|
||||
|
||||
response = {time_remaining: time_remaining, enemies: enemies}.to_json
|
||||
|
||||
File.write("./cache/rev2/time.txt", timestamp)
|
||||
File.write("./cache/rev2/data.json", response)
|
||||
else
|
||||
response = File.read("./cache/rev2/data.json")
|
||||
end
|
||||
|
||||
env.response.content_type = "application/json"
|
||||
env.response.headers.add("Access-Control-Allow-Origin", "*")
|
||||
response
|
||||
end
|
Loading…
Reference in New Issue
Block a user