Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: april maintenance #229

Merged
merged 1 commit into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
371 changes: 150 additions & 221 deletions package-lock.json

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
"#utils/*": "./src/utils/*"
},
"dependencies": {
"@logtail/node": "^0.4.16",
"@sentry/node": "^7.80.1",
"@logtail/node": "^0.4.21",
"@sentry/node": "^7.112.2",
"@teknologi-umum/nedb-promises": "^5.0.3",
"@teknologi-umum/pesto": "^1.0.0",
"carret": "^1.0.4",
Expand All @@ -35,9 +35,9 @@
"got": "^12.6.0",
"kleur": "^4.1.5",
"mongoose": "^8.2.4",
"qrcode": "^1.5.1",
"sanitize-html": "^2.12.1",
"telegraf": "^4.15.0",
"qrcode": "^1.5.3",
"sanitize-html": "^2.13.0",
"telegraf": "^4.16.3",
"tempura": "^0.4.0"
},
"devDependencies": {
Expand Down
6 changes: 3 additions & 3 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ Sentry.init({
enabled: process.env.NODE_ENV === "production",
environment: process.env.NODE_ENV,
sampleRate: 1.0,
tracesSampleRate: 0.2,
tracesSampleRate: 0.5,
integrations: [
new Sentry.Integrations.Http({ tracing: true }),
new Sentry.Integrations.Undici(),
Sentry.nativeNodeFetchIntegration(),
Sentry.httpIntegration({ tracing: true }),
...Sentry.autoDiscoverNodePerformanceMonitoringIntegrations()
]
});
Expand Down
35 changes: 14 additions & 21 deletions src/services/eval/crypto.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,29 @@
import got from "got";

export async function fetchCryptoCurrency(cryptoSymbol) {
if (typeof cryptoSymbol !== "string") {
throw "Simbol mata uang crypto harus berupa string";
}
if (!/^[A-Z]{3,8}(?:IDR|USDT)$/.test(cryptoSymbol)) {
throw `Simbol mata uang crypto ${cryptoSymbol} tidak valid`;
}
const requestSearchParams = new URLSearchParams();
requestSearchParams.set("symbol", cryptoSymbol.toUpperCase());
const response = await fetch(`https://gold.teknologiumum.com/crypto?${requestSearchParams.toString()}`);

const { statusCode, body } = await got.get(
`https://indodax.com/api/ticker/${cryptoSymbol.toLowerCase()}`,
{
responseType: "json",
throwHttpErrors: false
}
);

if (statusCode !== 200) {
if (response.status !== 200) {
throw `Gagal mendapatkan data crypto ${cryptoSymbol}`;
}


if (body.error_description !== undefined) {
throw body.error_description;
}

const body = await response.json();

return {
last: parseFloat(body.ticker.last),
buy: parseFloat(body.ticker.buy),
sell: parseFloat(body.ticker.sell),
high: parseFloat(body.ticker.high),
low: parseFloat(body.ticker.low)
symbol: body.symbol,
base_currency: body.base_currency,
quote_currency: body.quote_currency,
open: parseFloat(body.open),
high: parseFloat(body.high),
low: parseFloat(body.low),
last: parseFloat(body.last),
volume: parseFloat(body.volume),
date: new Date(body.date)
};
}
12 changes: 3 additions & 9 deletions src/services/eval/currency.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import got from "got";
import { SingleValueCache } from "#utils/cache.js";

// cache TTL: 10 minutes
Expand All @@ -9,18 +8,13 @@ const cache = new SingleValueCache(cacheTtl);

async function getCurrencyDictionary() {
const c = await cache.getOrCreate(async () => {
const { statusCode, body } = await got.get(
"https://gold.teknologiumum.com/currencies",
{
responseType: "json",
throwHttpErrors: false
}
);
const response = await fetch("https://gold.teknologiumum.com/currencies");

if (statusCode !== 200) {
if (response.status !== 200) {
throw "Gagal mendapatkan data forex";
}

const body = await response.json();

return body.reduce((currencyBySymbol, currency) => {
currencyBySymbol[currency.name] = currency;
Expand Down
21 changes: 8 additions & 13 deletions src/services/eval/stock.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import got from "got";

export async function fetchStock(stockCode) {
if (typeof stockCode !== "string") throw "Kode saham harus berupa string";
if (!/^[A-Z]{4}(?:-[A-Z][A-Z\d]{0,2})?$/.test(stockCode)) {
Expand All @@ -9,19 +7,17 @@ export async function fetchStock(stockCode) {
const requestSearchParams = new URLSearchParams();
requestSearchParams.set("stockCode", stockCode);

const { statusCode, body } = await got.get(
`https://gold.teknologiumum.com/stock?${requestSearchParams.toString()}`,
{
responseType: "json",
throwHttpErrors: false
}
const response = await fetch(
`https://gold.teknologiumum.com/stock?${requestSearchParams.toString()}`
);

if (statusCode !== 200) {
if (response.status !== 200) {
throw `Gagal mendapatkan data saham ${stockCode}`;
}

const response = {
const body = await response.json();

const mappedResponse = {
name: body.symbol,
close: body.close,
previous: body.open,
Expand All @@ -31,8 +27,7 @@ export async function fetchStock(stockCode) {
value: body.close
};

if (mappedResponse.name === "") throw stockCode;

if (response.name === "") throw stockCode;

return response;
return mappedResponse;
}
18 changes: 5 additions & 13 deletions src/services/snap/utils.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import got from "got";
import { DEFAULT_HEADERS } from "#utils/http.js";
import {
ERR_EMPTY_CODE,
Expand Down Expand Up @@ -27,10 +26,9 @@ export async function generateImage(code, lang) {
}

const linenr = code.split("\n").length;
const { body } = await got.post("https://graphene.teknologiumum.com/api", {
const response = await fetch("https://graphene.teknologiumum.com/api", {
headers: DEFAULT_HEADERS,
http2: true,
json: {
body: JSON.stringify({
code: code.replace(/^\s+|\s+$/g, ""), // trim extranous whitespace at the end of the code
lang: lang === "" ? null : lang,
theme: "github-dark-dimmed",
Expand All @@ -41,15 +39,9 @@ export async function generateImage(code, lang) {
colour: "#A0ADB6",
radius: 4
}
},
responseType: "buffer",
timeout: {
request: 60_000
},
retry: {
limit: 3
}
}),
cache: "no-cache"
});

return body;
return Buffer.from(await response.arrayBuffer());
}
3 changes: 1 addition & 2 deletions src/uptime.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import dotenv from "dotenv";
import got from "got";
import * as Sentry from "@sentry/node";
import { pathTo } from "#utils/path.js";

Expand All @@ -17,7 +16,7 @@
searchParams.set("ping", "0");
searchParams.set("status", "up");

await got.get(url + "?" + searchParams.toString());
await fetch(url + "?" + searchParams.toString());
}

for (;;) {
Expand All @@ -39,7 +38,7 @@

while (!done) {
// wait
await sleep(1000);

Check warning on line 41 in src/uptime.js

View workflow job for this annotation

GitHub Actions / Check

Unexpected `await` inside a loop
}

// How long do we need to sleep
Expand Down
Loading