Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- base : https://lahelu.com/
- req by : bang chandra
- note : 2 fungsi, search by query, dan nampilin rekomendasi
- pakai cursor buat next page
- node : v24.5.0
- last update : 23 september 2025
- by : wolep
- */
- const lahelu = {
- get field() {
- return {
- FOR_YOU: 5,
- FRESH: 6,
- VIRAL: 7
- }
- },
- _mintaJson: async function (pathName, urlSearchParams) {
- const url = new URL('https://lahelu.com')
- url.pathname = pathName
- url.search = new URLSearchParams(urlSearchParams)
- const response = await fetch(url)
- if (!response.ok) throw Error(`${response.status} ${response.statusText} on ${pathName}. payload from server:\n${await response.text() || '(kosong)'}`)
- const json = await response.json()
- return json
- },
- _serialize: function (json, onWhat, cursor) {
- const result = json.postInfos.map(p => {
- return {
- title: p.title || `(no title)`,
- hashtag: p.hashtags.join(', ') || `(no hastag)`,
- media: p?.content?.[0] || null
- }
- })
- if (!result.length) throw Error(`tidak ada data ${onWhat} di index cursor ${cursor}`)
- return result
- },
- search: async function (query, cursor = 0) {
- // validate string
- if (typeof (query) != 'string' || !query.trim().length) throw Error(`query harus string dan gak boleh kosong ya!`)
- const json = await this._mintaJson('/api/post/get-search', {
- query, cursor
- })
- return this._serialize(json, 'search', cursor)
- },
- recommendations: async function (field = this.field.FOR_YOU, cursor = 0) {
- // validate field
- if (!Object.values(this.field).includes(field)) throw Error(`invalid field value`)
- const json = await this._mintaJson('/api/post/get-recommendations', {
- field, cursor
- })
- return this._serialize(json, 'rekomendasi', cursor)
- }
- }
- // cara pakai
- lahelu.search('meme', 0)
- .then(console.log)
- .catch(e => console.log(e.message))
- /* output
- [
- {
- title: 'Meme halal hari ini',
- hashtag: 'relate',
- media: {
- type: 0,
- value: 'https://cache.lahelu.com/19e6ece1-6166-4a66-8395-885b18ec8f75.webp',
- width: 720,
- height: 398
- }
- },,... (dan objek lainnya)
- ]
- */
- /*
- atauu..
- lahelu.recommendations(lahelu.field.FOR_YOU, 0)
- .then(console.log)
- .catch(e => console.log(e.message))
- */
Advertisement
Add Comment
Please, Sign In to add comment