first commit
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
/**
|
||||
* iOS Location Spoofer Web
|
||||
*
|
||||
* Copyright (c) 2026 akudamatata (https://github.com/akudamatata/iOS-Location-Spoofer-Web)
|
||||
* Licensed under CC BY-NC-SA 4.0
|
||||
* ⚠️【特别声明】:本项目完全免费开源,严禁以任何形式进行二次售卖、转售、商业收费代搭建!
|
||||
*/
|
||||
|
||||
export const DEFAULT_LOC = {
|
||||
latitude: 39.90872,
|
||||
longitude: 116.39748,
|
||||
altitude: 44,
|
||||
horizontalAccuracy: 39,
|
||||
verticalAccuracy: 1000
|
||||
};
|
||||
|
||||
export function authOk(request, env) {
|
||||
const url = new URL(request.url);
|
||||
const token = url.searchParams.get('token');
|
||||
return !env.TOKEN || token === env.TOKEN;
|
||||
}
|
||||
|
||||
export function jsonResponse(data, status = 200) {
|
||||
return new Response(JSON.stringify(data), {
|
||||
status,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Access-Control-Allow-Origin': '*',
|
||||
'Cache-Control': 'no-store'
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export function errorResponse(message, status = 400) {
|
||||
return jsonResponse({ error: message }, status);
|
||||
}
|
||||
|
||||
export function corsHeaders() {
|
||||
return {
|
||||
'Access-Control-Allow-Origin': '*',
|
||||
'Access-Control-Allow-Methods': 'GET,POST,DELETE,OPTIONS',
|
||||
'Access-Control-Allow-Headers': 'Content-Type'
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/**
|
||||
* iOS Location Spoofer Web
|
||||
*
|
||||
* Copyright (c) 2026 akudamatata (https://github.com/akudamatata/iOS-Location-Spoofer-Web)
|
||||
* Licensed under CC BY-NC-SA 4.0
|
||||
* ⚠️【特别声明】:本项目完全免费开源,严禁以任何形式进行二次售卖、转售、商业收费代搭建!
|
||||
*/
|
||||
|
||||
import { authOk, jsonResponse, errorResponse, corsHeaders } from '../_utils.js';
|
||||
|
||||
export async function onRequestDelete(context) {
|
||||
const { request, env, params } = context;
|
||||
|
||||
if (!authOk(request, env)) {
|
||||
return errorResponse('unauthorized', 401);
|
||||
}
|
||||
|
||||
const id = params.id;
|
||||
|
||||
if (env.SPOOFER_DATA) {
|
||||
let favs = await env.SPOOFER_DATA.get('favorites', { type: 'json' }) || [];
|
||||
favs = favs.filter(f => f.id !== id);
|
||||
await env.SPOOFER_DATA.put('favorites', JSON.stringify(favs));
|
||||
}
|
||||
|
||||
return jsonResponse({ ok: true });
|
||||
}
|
||||
|
||||
export async function onRequestOptions() {
|
||||
return new Response(null, {
|
||||
status: 204,
|
||||
headers: corsHeaders()
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
/**
|
||||
* iOS Location Spoofer Web
|
||||
*
|
||||
* Copyright (c) 2026 akudamatata (https://github.com/akudamatata/iOS-Location-Spoofer-Web)
|
||||
* Licensed under CC BY-NC-SA 4.0
|
||||
* ⚠️【特别声明】:本项目完全免费开源,严禁以任何形式进行二次售卖、转售、商业收费代搭建!
|
||||
*/
|
||||
|
||||
import { authOk, jsonResponse, errorResponse, corsHeaders } from '../_utils.js';
|
||||
|
||||
export async function onRequestGet(context) {
|
||||
const { request, env } = context;
|
||||
|
||||
if (!authOk(request, env)) {
|
||||
return errorResponse('unauthorized', 401);
|
||||
}
|
||||
|
||||
let favs = [];
|
||||
if (env.SPOOFER_DATA) {
|
||||
favs = await env.SPOOFER_DATA.get('favorites', { type: 'json' }) || [];
|
||||
}
|
||||
|
||||
return jsonResponse(favs);
|
||||
}
|
||||
|
||||
export async function onRequestPost(context) {
|
||||
const { request, env } = context;
|
||||
|
||||
if (!authOk(request, env)) {
|
||||
return errorResponse('unauthorized', 401);
|
||||
}
|
||||
|
||||
try {
|
||||
const data = await request.json();
|
||||
let favs = [];
|
||||
if (env.SPOOFER_DATA) {
|
||||
favs = await env.SPOOFER_DATA.get('favorites', { type: 'json' }) || [];
|
||||
}
|
||||
|
||||
const fav = {
|
||||
id: Date.now().toString(36),
|
||||
name: (data.name || '未命名').slice(0, 30),
|
||||
latitude: data.latitude,
|
||||
longitude: data.longitude,
|
||||
altitude: data.altitude ?? null,
|
||||
horizontalAccuracy: data.horizontalAccuracy ?? null,
|
||||
verticalAccuracy: data.verticalAccuracy ?? null,
|
||||
createdAt: new Date().toISOString()
|
||||
};
|
||||
|
||||
favs.unshift(fav);
|
||||
if (favs.length > 100) favs.pop();
|
||||
|
||||
if (env.SPOOFER_DATA) {
|
||||
await env.SPOOFER_DATA.put('favorites', JSON.stringify(favs));
|
||||
}
|
||||
|
||||
return jsonResponse(fav);
|
||||
} catch (err) {
|
||||
return errorResponse('bad json');
|
||||
}
|
||||
}
|
||||
|
||||
export async function onRequestOptions() {
|
||||
return new Response(null, {
|
||||
status: 204,
|
||||
headers: corsHeaders()
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
/**
|
||||
* iOS Location Spoofer Web
|
||||
*
|
||||
* Copyright (c) 2026 akudamatata (https://github.com/akudamatata/iOS-Location-Spoofer-Web)
|
||||
* Licensed under CC BY-NC-SA 4.0
|
||||
* ⚠️【特别声明】:本项目完全免费开源,严禁以任何形式进行二次售卖、转售、商业收费代搭建!
|
||||
*/
|
||||
|
||||
export async function onRequestGet(context) {
|
||||
const { request, env } = context;
|
||||
|
||||
// Fetch the static index.html from Cloudflare Pages ASSETS
|
||||
const response = await env.ASSETS.fetch(request);
|
||||
|
||||
if (!response.ok) {
|
||||
return response;
|
||||
}
|
||||
|
||||
const hasToken = Boolean(env.TOKEN);
|
||||
const amapKey = env.AMAP_KEY || '';
|
||||
|
||||
const configScript = `<script>window.__CFG__=${JSON.stringify({ hasToken, amapKey })};</script>`;
|
||||
|
||||
// Use HTMLRewriter to inject the config script just before the closing </head> tag
|
||||
return new HTMLRewriter()
|
||||
.on('head', {
|
||||
element(element) {
|
||||
element.append(configScript, { html: true });
|
||||
}
|
||||
})
|
||||
.transform(response);
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
/**
|
||||
* iOS Location Spoofer Web
|
||||
*
|
||||
* Copyright (c) 2026 akudamatata (https://github.com/akudamatata/iOS-Location-Spoofer-Web)
|
||||
* Licensed under CC BY-NC-SA 4.0
|
||||
* ⚠️【特别声明】:本项目完全免费开源,严禁以任何形式进行二次售卖、转售、商业收费代搭建!
|
||||
*/
|
||||
|
||||
export async function onRequestGet(context) {
|
||||
const { request, env } = context;
|
||||
|
||||
// Fetch the static asset from Cloudflare Pages
|
||||
const response = await env.ASSETS.fetch(request);
|
||||
|
||||
if (!response.ok) {
|
||||
return new Response('Not found', { status: 404 });
|
||||
}
|
||||
|
||||
let content = await response.text();
|
||||
|
||||
const url = new URL(request.url);
|
||||
const host = request.headers.get('host') || url.host;
|
||||
const protocol = request.headers.get('x-forwarded-proto') || url.protocol.replace(':', '');
|
||||
const tVal = url.searchParams.get('token') || '';
|
||||
|
||||
content = content.replace(/你的域名/g, host);
|
||||
content = content.replace(/你的Token/g, tVal);
|
||||
|
||||
if (protocol === 'https') {
|
||||
content = content.replace(/http:\/\/localhost:8080/g, 'https://' + host);
|
||||
}
|
||||
|
||||
return new Response(content, {
|
||||
status: 200,
|
||||
headers: {
|
||||
'Content-Type': 'text/plain; charset=utf-8',
|
||||
'Access-Control-Allow-Origin': '*'
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
/**
|
||||
* iOS Location Spoofer Web
|
||||
*
|
||||
* Copyright (c) 2026 akudamatata (https://github.com/akudamatata/iOS-Location-Spoofer-Web)
|
||||
* Licensed under CC BY-NC-SA 4.0
|
||||
* ⚠️【特别声明】:本项目完全免费开源,严禁以任何形式进行二次售卖、转售、商业收费代搭建!
|
||||
*/
|
||||
|
||||
import { DEFAULT_LOC, authOk, jsonResponse, errorResponse, corsHeaders } from './_utils.js';
|
||||
|
||||
export async function onRequestGet(context) {
|
||||
const { request, env } = context;
|
||||
|
||||
if (!authOk(request, env)) {
|
||||
return errorResponse('unauthorized', 401);
|
||||
}
|
||||
|
||||
let loc = DEFAULT_LOC;
|
||||
if (env.SPOOFER_DATA) {
|
||||
loc = await env.SPOOFER_DATA.get('loc', { type: 'json' }) || DEFAULT_LOC;
|
||||
}
|
||||
|
||||
return jsonResponse(loc);
|
||||
}
|
||||
|
||||
export async function onRequestOptions() {
|
||||
return new Response(null, {
|
||||
status: 204,
|
||||
headers: corsHeaders()
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
/**
|
||||
* iOS Location Spoofer Web
|
||||
*
|
||||
* Copyright (c) 2026 akudamatata (https://github.com/akudamatata/iOS-Location-Spoofer-Web)
|
||||
* Licensed under CC BY-NC-SA 4.0
|
||||
* ⚠️【特别声明】:本项目完全免费开源,严禁以任何形式进行二次售卖、转售、商业收费代搭建!
|
||||
*/
|
||||
|
||||
import { DEFAULT_LOC, authOk, jsonResponse, errorResponse, corsHeaders } from './_utils.js';
|
||||
|
||||
export async function onRequestPost(context) {
|
||||
const { request, env } = context;
|
||||
|
||||
if (!authOk(request, env)) {
|
||||
return errorResponse('unauthorized', 401);
|
||||
}
|
||||
|
||||
try {
|
||||
const data = await request.json();
|
||||
let current = DEFAULT_LOC;
|
||||
|
||||
if (env.SPOOFER_DATA) {
|
||||
current = await env.SPOOFER_DATA.get('loc', { type: 'json' }) || DEFAULT_LOC;
|
||||
}
|
||||
|
||||
const updated = { ...current };
|
||||
if (typeof data.latitude === 'number') updated.latitude = data.latitude;
|
||||
if (typeof data.longitude === 'number') updated.longitude = data.longitude;
|
||||
if (typeof data.altitude === 'number') updated.altitude = data.altitude;
|
||||
if (typeof data.horizontalAccuracy === 'number') updated.horizontalAccuracy = data.horizontalAccuracy;
|
||||
if (typeof data.verticalAccuracy === 'number') updated.verticalAccuracy = data.verticalAccuracy;
|
||||
|
||||
if (env.SPOOFER_DATA) {
|
||||
await env.SPOOFER_DATA.put('loc', JSON.stringify(updated));
|
||||
}
|
||||
|
||||
return jsonResponse(updated);
|
||||
} catch (err) {
|
||||
return errorResponse('bad json');
|
||||
}
|
||||
}
|
||||
|
||||
export async function onRequestOptions() {
|
||||
return new Response(null, {
|
||||
status: 204,
|
||||
headers: corsHeaders()
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
/**
|
||||
* iOS Location Spoofer Web
|
||||
*
|
||||
* Copyright (c) 2026 akudamatata (https://github.com/akudamatata/iOS-Location-Spoofer-Web)
|
||||
* Licensed under CC BY-NC-SA 4.0
|
||||
* ⚠️【特别声明】:本项目完全免费开源,严禁以任何形式进行二次售卖、转售、商业收费代搭建!
|
||||
*/
|
||||
|
||||
import { authOk, jsonResponse, errorResponse, corsHeaders } from './_utils.js';
|
||||
|
||||
export async function onRequestGet(context) {
|
||||
const { request, env } = context;
|
||||
|
||||
if (!authOk(request, env)) {
|
||||
return errorResponse('unauthorized', 401);
|
||||
}
|
||||
|
||||
return jsonResponse({ ok: true });
|
||||
}
|
||||
|
||||
export async function onRequestOptions() {
|
||||
return new Response(null, {
|
||||
status: 204,
|
||||
headers: corsHeaders()
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user