|
|
@ -14,46 +14,55 @@ import { |
|
|
|
dotenv.config({ path: path.resolve(__dirname, "../.env.local") }) |
|
|
|
dotenv.config({ path: path.resolve(__dirname, "../.env.local") }) |
|
|
|
import db from "../db/index" |
|
|
|
import db from "../db/index" |
|
|
|
import axios from "axios" |
|
|
|
import axios from "axios" |
|
|
|
|
|
|
|
import { getTonProxy } from "./helpers" |
|
|
|
|
|
|
|
|
|
|
|
const nftApi = new NFTApi() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const DOMAIN_MOCKS = ["https://wolkonsky.com", "https://zhleb.ru"] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const DOMAINS_COLLECTION_ADDRESS = "EQC3dNlesgVD8YbAazcauIrXBPfiVhMMr5YYk2in0Mtsz0Bz" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// const main = async () => {
|
|
|
|
|
|
|
|
// DOMAIN_MOCKS.forEach(async (item) => {
|
|
|
|
|
|
|
|
// await db.domain.upsert({
|
|
|
|
|
|
|
|
// where: {
|
|
|
|
|
|
|
|
// address: item,
|
|
|
|
|
|
|
|
// },
|
|
|
|
|
|
|
|
// update: {},
|
|
|
|
|
|
|
|
// create: { address: item },
|
|
|
|
|
|
|
|
// })
|
|
|
|
|
|
|
|
// })
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
interface SearchNFTItemsParams { |
|
|
|
interface SearchNFTItemsParams { |
|
|
|
limit: number |
|
|
|
limit: number |
|
|
|
offset: number |
|
|
|
offset: number |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const wait = (time:number) => new Promise((resolve)=>setTimeout(()=>resolve(true),time ))
|
|
|
|
|
|
|
|
|
|
|
|
const searchNFTItems = async ({ limit, offset }: SearchNFTItemsParams) => { |
|
|
|
const searchNFTItems = async ({ limit, offset }: SearchNFTItemsParams) => { |
|
|
|
|
|
|
|
try{ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
console.log(`Start search limit:${limit}, offset:${offset}`) |
|
|
|
console.log(`Start search limit:${limit}, offset:${offset}`) |
|
|
|
|
|
|
|
await wait(1000) |
|
|
|
const { data } = await axios.get( |
|
|
|
const { data } = await axios.get( |
|
|
|
`https://tonapi.io/v1/nft/searchItems?collection=EQC3dNlesgVD8YbAazcauIrXBPfiVhMMr5YYk2in0Mtsz0Bz&include_on_sale=false&limit=${limit}&offset=${offset}` |
|
|
|
`https://tonapi.io/v1/nft/searchItems?collection=EQC3dNlesgVD8YbAazcauIrXBPfiVhMMr5YYk2in0Mtsz0Bz&include_on_sale=false&limit=${limit}&offset=${offset}`, |
|
|
|
) |
|
|
|
{ |
|
|
|
console.log(`Success search: ${data.nft_items.length} items`) |
|
|
|
headers:{ |
|
|
|
|
|
|
|
// 'Authorization': 'Bearer '+ '6c456b1e31217a79e121dcb9b506c280358d58bc86659bdbac1d737bfc3691fb',
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
)
|
|
|
|
return data.nft_items |
|
|
|
return data.nft_items |
|
|
|
|
|
|
|
} catch (e){ |
|
|
|
|
|
|
|
return searchNFTItems({ limit, offset }) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const portion = 1000 |
|
|
|
const portion = 1000 |
|
|
|
|
|
|
|
|
|
|
|
const main = async () => { |
|
|
|
const fetchTonSite = async (url: string) => { |
|
|
|
console.time("DOMAINWATCH") |
|
|
|
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)=>{ |
|
|
|
// Receive typed array of owner nfts
|
|
|
|
// Receive typed array of owner nfts
|
|
|
|
let count = 0 |
|
|
|
let count = 0 |
|
|
|
while (true) { |
|
|
|
while (true) { |
|
|
|
|
|
|
|
// в nftItems 1000 сайтов
|
|
|
|
const nftItems = await searchNFTItems({ |
|
|
|
const nftItems = await searchNFTItems({ |
|
|
|
limit: portion, |
|
|
|
limit: portion, |
|
|
|
offset: count * portion, |
|
|
|
offset: count * portion, |
|
|
@ -63,25 +72,27 @@ const main = async () => { |
|
|
|
for (let i = 0; i < nftItems.length; i++) { |
|
|
|
for (let i = 0; i < nftItems.length; i++) { |
|
|
|
const nftDomainItem = nftItems[i] |
|
|
|
const nftDomainItem = nftItems[i] |
|
|
|
if (nftDomainItem.dns) { |
|
|
|
if (nftDomainItem.dns) { |
|
|
|
await db.nftDomain.upsert({ |
|
|
|
fetchTonSite(nftDomainItem.dns) |
|
|
|
where: { |
|
|
|
.then(async (dmn) => { |
|
|
|
address: nftDomainItem.dns, |
|
|
|
console.log("success dmn", dmn) |
|
|
|
}, |
|
|
|
await db.nftDomain.upsert({ |
|
|
|
update: { available: false, address: nftDomainItem.dns }, |
|
|
|
where: { |
|
|
|
create: { available: false, address: nftDomainItem.dns }, |
|
|
|
address: `http://${dmn}`, |
|
|
|
}) |
|
|
|
}, |
|
|
|
|
|
|
|
update: { available: false, address: `http://${dmn}` }, |
|
|
|
|
|
|
|
create: { available: false, address: `http://${dmn}` }, |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
.catch(() => {}) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
count++ |
|
|
|
count++ |
|
|
|
continue |
|
|
|
continue |
|
|
|
} |
|
|
|
} |
|
|
|
console.timeEnd("DOMAINWATCH") |
|
|
|
|
|
|
|
break |
|
|
|
break |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
console.log('Finish fetch nft') |
|
|
|
|
|
|
|
setTimeout(()=>{resolve(true)}, 10000) |
|
|
|
main() |
|
|
|
}) |
|
|
|
.then(() => console.log("finish domain watcher")) |
|
|
|
|
|
|
|
.catch((e) => console.log("error in domain watcher", e)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export default {} |
|
|
|
export default main |
|
|
|