Initial commit
This commit is contained in:
@@ -0,0 +1,133 @@
|
||||
import { createCloudApi, createLocalApi } from '../api'
|
||||
import { appConfig } from '../config'
|
||||
import { fetchFingerprint, fetchProxy } from './cloud'
|
||||
|
||||
export async function fetchProfiles(params) {
|
||||
const api = createCloudApi()
|
||||
const { data } = await api.get('/browser/profile/list', { params })
|
||||
return data
|
||||
}
|
||||
|
||||
export async function fetchProfile(profileId) {
|
||||
const api = createCloudApi()
|
||||
const { data } = await api.get(`/browser/profile/${profileId}`)
|
||||
return data
|
||||
}
|
||||
|
||||
export async function createProfile(payload) {
|
||||
const api = createCloudApi()
|
||||
const { data } = await api.post('/browser/profile', payload)
|
||||
return data
|
||||
}
|
||||
|
||||
export async function updateProfile(payload) {
|
||||
const api = createCloudApi()
|
||||
const { data } = await api.put('/browser/profile', payload)
|
||||
return data
|
||||
}
|
||||
|
||||
export async function deleteProfile(profileId) {
|
||||
const api = createCloudApi()
|
||||
const { data } = await api.delete(`/browser/profile/${profileId}`)
|
||||
return data
|
||||
}
|
||||
|
||||
function buildFingerprintPayload(item) {
|
||||
if (!item) {
|
||||
return null
|
||||
}
|
||||
return {
|
||||
fingerprintId: item.fingerprintId,
|
||||
browserFamily: item.browserFamily,
|
||||
userAgent: item.userAgent,
|
||||
locale: item.locale,
|
||||
timezone: item.timezone,
|
||||
geoCountry: item.geoCountry,
|
||||
screenWidth: item.screenWidth,
|
||||
screenHeight: item.screenHeight,
|
||||
webRtcPolicy: item.webRtcPolicy,
|
||||
canvasPolicy: item.canvasPolicy,
|
||||
webglPolicy: item.webglPolicy,
|
||||
audioPolicy: item.audioPolicy,
|
||||
fontPolicy: item.fontPolicy,
|
||||
payload: item.encryptedPayload
|
||||
}
|
||||
}
|
||||
|
||||
function buildProxyPayload(item) {
|
||||
if (!item) {
|
||||
return null
|
||||
}
|
||||
if (item.proxyType === 'direct') {
|
||||
return null
|
||||
}
|
||||
return {
|
||||
proxy_type: item.proxyType,
|
||||
host: item.host,
|
||||
port: Number(item.port),
|
||||
username: item.username || null
|
||||
}
|
||||
}
|
||||
|
||||
export async function launchProfile(profileId, options = {}) {
|
||||
const profileRes = await fetchProfile(profileId)
|
||||
const profile = profileRes.data
|
||||
const [proxyRes, fingerprintRes] = await Promise.all([
|
||||
profile.proxyId ? fetchProxy(profile.proxyId) : Promise.resolve(null),
|
||||
profile.fingerprintId ? fetchFingerprint(profile.fingerprintId) : Promise.resolve(null)
|
||||
])
|
||||
|
||||
const proxy = proxyRes?.data || null
|
||||
const fingerprint = fingerprintRes?.data || null
|
||||
const localApi = createLocalApi()
|
||||
const runtimePath = profile.browserEngine === 'firefox'
|
||||
? (appConfig.camoufoxRuntimePath || null)
|
||||
: (appConfig.chromiumRuntimePath || null)
|
||||
|
||||
const payload = {
|
||||
profile_id: String(profile.profileId),
|
||||
browser_engine: profile.browserEngine,
|
||||
runtime_path: runtimePath,
|
||||
start_url: options.startUrl || 'https://www.browserscan.net',
|
||||
headless: false,
|
||||
browser_args: [],
|
||||
proxy: buildProxyPayload(proxy),
|
||||
fingerprint: buildFingerprintPayload(fingerprint),
|
||||
proxy_type: proxy?.proxyType || null,
|
||||
proxy_host: proxy?.host || null,
|
||||
proxy_port: proxy?.port ? Number(proxy.port) : null
|
||||
}
|
||||
|
||||
const { data } = await localApi.post(`/profiles/${profileId}/launch`, payload)
|
||||
return data
|
||||
}
|
||||
|
||||
export async function closeProfile(profileId) {
|
||||
const api = createLocalApi()
|
||||
const { data } = await api.post(`/profiles/${profileId}/close`)
|
||||
return data
|
||||
}
|
||||
|
||||
export async function fetchRunningProfiles() {
|
||||
const api = createLocalApi()
|
||||
const { data } = await api.get('/profiles/running')
|
||||
return data
|
||||
}
|
||||
|
||||
export async function fetchRuntimeStatus() {
|
||||
const api = createLocalApi()
|
||||
const { data } = await api.get('/runtime/status')
|
||||
return data
|
||||
}
|
||||
|
||||
export async function fetchRuntimeConfig() {
|
||||
const api = createLocalApi()
|
||||
const { data } = await api.get('/runtime/config')
|
||||
return data
|
||||
}
|
||||
|
||||
export async function saveRuntimeConfig(payload) {
|
||||
const api = createLocalApi()
|
||||
const { data } = await api.put('/runtime/config', payload)
|
||||
return data
|
||||
}
|
||||
Reference in New Issue
Block a user