From c10393f14644e6a807c4eebdaadfd6b76c71fc7f Mon Sep 17 00:00:00 2001
From: Adrian Ardizza
Date: Mon, 1 Aug 2022 15:44:29 +0700
Subject: [PATCH] Implement TrustPositif Checking & Refactor Index (#29)
* Implement TrustPositif checking
* Moved websiteSections to own file in _data, move TrustPositif fetching to getStaticProps
* Split TP check request to chunks of 100 websites at a time
* Add TP indicator to registered but inaccessible websites
* Added extra explanation for TrustPositive status
* fix: await promise
* fix: grammar error
* feat: implement basic trycatching
Co-authored-by: Christopher Angelo
---
package.json | 1 +
src/_data/sections.tsx | 41 ++++++++++++
src/components/WebsiteEntry.tsx | 25 ++++++-
src/functions/fetchTrustPositif.ts | 56 ++++++++++++++++
src/modules/ExplanationSection.tsx | 21 ++++--
src/pages/api/fetchTrustPositif.ts | 13 ++++
src/pages/index.tsx | 104 ++++++++---------------------
yarn.lock | 5 ++
8 files changed, 181 insertions(+), 85 deletions(-)
create mode 100644 src/_data/sections.tsx
create mode 100644 src/functions/fetchTrustPositif.ts
create mode 100644 src/pages/api/fetchTrustPositif.ts
diff --git a/package.json b/package.json
index 14bfa0d..10e57af 100644
--- a/package.json
+++ b/package.json
@@ -22,6 +22,7 @@
"@next/bundle-analyzer": "^12.1.0",
"autoprefixer": "^10.4.0",
"fuse.js": "^6.6.2",
+ "https": "^1.0.0",
"next": "^12.1.0",
"next-compose-plugins": "^2.2.1",
"next-seo": "^5.1.0",
diff --git a/src/_data/sections.tsx b/src/_data/sections.tsx
new file mode 100644
index 0000000..3c4def1
--- /dev/null
+++ b/src/_data/sections.tsx
@@ -0,0 +1,41 @@
+import { devStarterPack, idnStarterPack, linuxStarterPack, websiteListUSA } from './websites'
+
+export const websiteSections = [
+ {
+ title: 'Indonesia Starterpack',
+ description: Situs atau service ini terpopuler dengan orang Indonesia
,
+ sites: idnStarterPack
+ },
+ {
+ title: 'Essential Developer Toolkit',
+ description: Service yang ✨ anak bangsa ✨ mungkin akan pakai saat membuat app
,
+ sites: devStarterPack
+ },
+ {
+ title: 'Top websites USA',
+ description: (
+ <>
+
+ 2022 Top websites in the USA. Sumber data website diambil dari{' '}
+
+ semrush.com
+
+
+
+ Catatan: Ada beberapa website ditiadakan karena tidak berhubungan
+
+ >
+ ),
+ sites: websiteListUSA
+ },
+ {
+ title: 'Linux Starterpack',
+ description: Service yang sering dipakai Linux user 🐧
,
+ sites: linuxStarterPack
+ }
+]
diff --git a/src/components/WebsiteEntry.tsx b/src/components/WebsiteEntry.tsx
index 5a287b8..619c916 100644
--- a/src/components/WebsiteEntry.tsx
+++ b/src/components/WebsiteEntry.tsx
@@ -1,3 +1,4 @@
+/* eslint-disable @next/next/no-img-element */
import { AlertCircle, Check, HelpCircle, X } from 'react-feather'
import { SimpleIcon } from 'simple-icons'
@@ -12,10 +13,15 @@ interface WebsiteEntryProps {
*/
registered?: boolean
+ /**
+ * Blocked in Trust Positif's Network - Checked via https://trustpositif.kominfo.go.id
+ */
+ trustPositif?: boolean
+
/**
* Blocked in Indihome's Network - Checked via https://indi.wtf
*/
- blocked?: boolean
+ indiWtf?: boolean
}
const LoadingSpinnerIcon = () => (
@@ -45,10 +51,13 @@ const LoadingSpinnerIcon = () => (
export const WebsiteEntry = ({
website,
registered = false,
- blocked = false
+ indiWtf = false,
+ trustPositif = false
}: WebsiteEntryProps) => {
const size = 32
+ const blocked = indiWtf || trustPositif
+
return (
Registered but inaccessible
+ {trustPositif && (
+
+ TP
+
+ )}
>
)
) : !blocked ? (
@@ -96,7 +110,12 @@ export const WebsiteEntry = ({
>
) : (
<>
- Blocked
+ Blocked{' '}
+ {trustPositif && (
+
+ TP
+
+ )}
>
)}
diff --git a/src/functions/fetchTrustPositif.ts b/src/functions/fetchTrustPositif.ts
new file mode 100644
index 0000000..b2c5a94
--- /dev/null
+++ b/src/functions/fetchTrustPositif.ts
@@ -0,0 +1,56 @@
+import https from 'https'
+
+import { devStarterPack, idnStarterPack, linuxStarterPack, websiteListUSA } from '../_data/websites'
+
+const allWebsitesCombined = [
+ devStarterPack,
+ idnStarterPack,
+ linuxStarterPack,
+ websiteListUSA
+].flat()
+
+const httpsAgent = new https.Agent({
+ rejectUnauthorized: false
+})
+
+export const fetchTrustPositif = async () => {
+ try {
+ const requestChunks = Array.from(
+ { length: Math.ceil(allWebsitesCombined.length / 100) },
+ (_, i) => allWebsitesCombined.slice(i * 100, i * 100 + 100)
+ )
+
+ const requests: Promise>[] = []
+
+ requestChunks.forEach((chunk) => {
+ requests.push(
+ fetch('https://trustpositif.kominfo.go.id/Rest_server/getrecordsname_home', {
+ method: 'POST',
+ header: {},
+ body: new URLSearchParams({
+ name: chunk
+ .map((item) => item.website.replace(/(https?:\/\/)/, '').replace(/www\./, ''))
+ .join('\n')
+ }),
+ agent: httpsAgent
+ } as any)
+ .then((res) => res.json())
+ .then((res) => {
+ let trustPositifStatus: Record = {}
+ res.values.forEach((item: any) => {
+ trustPositifStatus[item.Domain] = item.Status === 'Ada'
+ })
+ return trustPositifStatus
+ })
+ )
+ })
+
+ const trustPositifData = await Promise.all(requests)
+
+ return Object.assign({}, ...trustPositifData)
+ } catch (e) {
+ console.error(e)
+
+ return {}
+ }
+}
diff --git a/src/modules/ExplanationSection.tsx b/src/modules/ExplanationSection.tsx
index 32195d8..8a8b4d0 100644
--- a/src/modules/ExplanationSection.tsx
+++ b/src/modules/ExplanationSection.tsx
@@ -38,7 +38,7 @@ export const ExplanationSection = () => {
Selain itu, semua situs dibawah akan diperiksa status terblokirnya menggunakan jaringan
- IndiHome dan Sigma (courtesy of{' '}
+ IndiHome, Sigma (courtesy of{' '}
indi.wtf
{' '}
@@ -46,13 +46,24 @@ export const ExplanationSection = () => {
Frans Allen
- ). Jika situs tersebut diblokir dari jaringan IndiHome dan tidak terdaftar di situs PSE,
- maka status website akan berubah menjadi "
- BLOCKED ".
+ ) serta melalui pengecekan langsung ke sistem TrustPositif milik Kominfo yang digunakan
+ untuk melakukan pemblokiran.
- Pemilik situs akan mencoba untuk menyajikan data yang terbaru dan terakurat. Jika ada
+ Jika situs tersebut diblokir dari jaringan IndiHome dan tidak terdaftar di situs PSE, maka
+ status website akan berubah menjadi
+ BLOCKED .
+
+
+
+ Situs yang terdaftar pada sistem TrustPositif juga akan memiliki keterangan{' '}
+ TP yang menandakan bahwa website terdaftar pada database pemblokiran resmi
+ miliki Kominfo.
+
+
+
+ Pemilik situs akan berusaha untuk menyajikan data yang terbaru dan terakurat. Jika ada
masalah, dimohon untuk mengontak saya melalui link di footer!
diff --git a/src/pages/api/fetchTrustPositif.ts b/src/pages/api/fetchTrustPositif.ts
new file mode 100644
index 0000000..f995ed6
--- /dev/null
+++ b/src/pages/api/fetchTrustPositif.ts
@@ -0,0 +1,13 @@
+import { NextApiHandler } from 'next'
+
+import { fetchTrustPositif } from '../../functions/fetchTrustPositif'
+
+const handler: NextApiHandler = async (req, res) => {
+ const trustPositifData = await fetchTrustPositif()
+
+ return res
+ .setHeader('Cache-Control', 'public, s-maxage=60, stale-while-revalidate=3600')
+ .json(trustPositifData)
+}
+
+export default handler
diff --git a/src/pages/index.tsx b/src/pages/index.tsx
index 54041f8..2720fe4 100644
--- a/src/pages/index.tsx
+++ b/src/pages/index.tsx
@@ -4,8 +4,10 @@ import { NextSeo } from 'next-seo'
import * as React from 'react'
import FullPSEData from '../../public/data.json'
+import { websiteSections } from '../_data/sections'
import { devStarterPack, idnStarterPack, linuxStarterPack, websiteListUSA } from '../_data/websites'
import { WebsiteEntry } from '../components/WebsiteEntry'
+import { fetchTrustPositif } from '../functions/fetchTrustPositif'
import { ExplanationSection, ManualSearchSection, WhatIsThisSection } from '../modules'
import type { PSEData } from '../types/PSEData'
import { generateBlockList } from './api/fetchBlocked'
@@ -34,6 +36,7 @@ const allWebsitesCombined = [
interface IndexPageProps {
PSEData: Record
blockData: Record
+ trustPositifData: Record
}
export async function getStaticProps(
@@ -46,18 +49,18 @@ export async function getStaticProps(
})
const blockData = await generateBlockList()
+ const trustPositifData = await fetchTrustPositif()
return {
- props: { PSEData: sites, blockData },
+ props: { PSEData: sites, blockData, trustPositifData },
revalidate: 5 * 60
}
}
-const IndexPage = ({ PSEData: data, blockData }: IndexPageProps) => {
+const IndexPage = ({ PSEData: data, blockData, trustPositifData }: IndexPageProps) => {
return (
<>
-
@@ -69,80 +72,27 @@ const IndexPage = ({ PSEData: data, blockData }: IndexPageProps) => {
-
- Indonesia Starterpack
- Situs atau service ini terpopuler dengan orang Indonesia
-
- {idnStarterPack.map((website) => (
-
- ))}
-
-
-
-
- Essential developer toolkit
- Service yang ✨ anak bangsa ✨ mungkin akan pakai saat membuat app
-
-
- {devStarterPack.map((website) => (
-
- ))}
-
-
-
-
- Top websites USA
-
- 2022 Top websites in the USA. Sumber data website diambil dari{' '}
-
- semrush.com
-
-
-
- Catatan: Ada beberapa website ditiadakan karena tidak berhubungan
-
-
- {websiteListUSA.map((website) => (
-
- ))}
-
-
-
-
- Linux Starterpack
- Service yang sering dipakai Linux user 🐧
-
-
- {linuxStarterPack.map((website) => (
-
- ))}
-
-
+ {websiteSections.map((item) => (
+
+ {item.title}
+ {item.description}
+
+ {item.sites.map((website) => (
+
+ ))}
+
+
+ ))}
diff --git a/yarn.lock b/yarn.lock
index d23ead1..8a9f677 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -1389,6 +1389,11 @@ has@^1.0.3:
dependencies:
function-bind "^1.1.1"
+https@^1.0.0:
+ version "1.0.0"
+ resolved "https://registry.yarnpkg.com/https/-/https-1.0.0.tgz#3c37c7ae1a8eeb966904a2ad1e975a194b7ed3a4"
+ integrity sha512-4EC57ddXrkaF0x83Oj8sM6SLQHAWXw90Skqu2M4AEWENZ3F02dFJE/GARA8igO79tcgYqGrD7ae4f5L3um2lgg==
+
husky@^8.0.1:
version "8.0.1"
resolved "https://registry.yarnpkg.com/husky/-/husky-8.0.1.tgz#511cb3e57de3e3190514ae49ed50f6bc3f50b3e9"