Searching.ton
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

99 lines
2.4 KiB

2 years ago
import dotenv from "dotenv"
import path from "path"
import tonweb from "tonweb"
import {
JettonApi,
DNSApi,
NFTApi,
RawBlockchainApi,
SubscriptionApi,
TraceApi,
WalletApi,
Configuration,
} from "tonapi-sdk-js"
dotenv.config({ path: path.resolve(__dirname, "../.env.local") })
import db from "../db/index"
import axios from "axios"
2 years ago
import { getTonProxy } from "./helpers"
2 years ago
interface SearchNFTItemsParams {
limit: number
offset: number
}
2 years ago
const wait = (time:number) => new Promise((resolve)=>setTimeout(()=>resolve(true),time ))
2 years ago
const searchNFTItems = async ({ limit, offset }: SearchNFTItemsParams) => {
2 years ago
try{
2 years ago
console.log(`Start search limit:${limit}, offset:${offset}`)
2 years ago
await wait(1000)
2 years ago
const { data } = await axios.get(
2 years ago
`https://tonapi.io/v1/nft/searchItems?collection=EQC3dNlesgVD8YbAazcauIrXBPfiVhMMr5YYk2in0Mtsz0Bz&include_on_sale=false&limit=${limit}&offset=${offset}`,
{
headers:{
// 'Authorization': 'Bearer '+ '6c456b1e31217a79e121dcb9b506c280358d58bc86659bdbac1d737bfc3691fb',
}
}
)
2 years ago
return data.nft_items
2 years ago
} catch (e){
return searchNFTItems({ limit, offset })
}
2 years ago
}
const portion = 1000
2 years ago
const fetchTonSite = async (url: string) => {
const urlToFetch = `http://${url}/`
const response = await axios.get(urlToFetch, {
proxy: getTonProxy(),
})
if (!response.data) {
console.log("Error fetch")
throw "error"
}
return url
}
const main = async () => new Promise(async (resolve)=>{
2 years ago
// Receive typed array of owner nfts
let count = 0
while (true) {
2 years ago
// в nftItems 1000 сайтов
2 years ago
const nftItems = await searchNFTItems({
limit: portion,
offset: count * portion,
})
if (nftItems.length) {
for (let i = 0; i < nftItems.length; i++) {
const nftDomainItem = nftItems[i]
if (nftDomainItem.dns) {
2 years ago
fetchTonSite(nftDomainItem.dns)
.then(async (dmn) => {
console.log("success dmn", dmn)
await db.nftDomain.upsert({
where: {
address: `http://${dmn}`,
},
update: { available: false, address: `http://${dmn}` },
create: { available: false, address: `http://${dmn}` },
})
})
.catch(() => {})
2 years ago
}
}
count++
continue
}
break
}
2 years ago
console.log('Finish fetch nft')
setTimeout(()=>{resolve(true)}, 10000)
})
2 years ago
2 years ago
export default main