Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .idea/cf-worker-api.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 15 additions & 2 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

122 changes: 119 additions & 3 deletions public/index.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html lang="zh-CN" data-theme="light">
<html lang="zh-CN" data-theme="light" xmlns="http://www.w3.org/1999/html">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
Expand Down Expand Up @@ -155,7 +155,17 @@ <h2 class="text-center mb-4">🔐 OpenList Token 获取工具</h2>
<label for="refresh-token" class="form-label">刷新秘钥</label>
<textarea id="refresh-token" class="form-control" rows="3" readonly onclick="autoCopy(this)"></textarea>
</div>

<div class="mb-3">
<label for="sharepoint-url" class="form-label">SharePoint Site URL</label>
<label for="sharepoint-url"></label><input type="text" id="sharepoint-url" class="form-control">
</div>
<div class="d-grid gap-2 mb-3">
<button class="btn btn-primary" onclick="getSiteID()">获取 SharePoint 站点ID</button>
</div>
<div class="mb-3">
<label for="sharepoint-id" class="form-label">SharePoint Site URL</label>
<textarea id="sharepoint-id" class="form-control" rows="3" readonly onclick="autoCopy(this)"></textarea>
</div>
<div class="text-muted text-center">
<p style="text-align:center">
本工具所有信息只以Cookie形式存储于浏览器本地<br>
Expand All @@ -165,7 +175,6 @@ <h2 class="text-center mb-4">🔐 OpenList Token 获取工具</h2>
</p>
</div>
</div>
</div>

<script>
let intervalId;
Expand Down Expand Up @@ -364,6 +373,113 @@ <h2 class="text-center mb-4">🔐 OpenList Token 获取工具</h2>
}
}


// 获取站点ID
function getSiteID() {
const siteUrl = document.getElementById("sharepoint-url").value.trim();
const access_token = document.getElementById("access-token").value.trim();
const refresh_token = document.getElementById("refresh-token").value.trim();
const client_uid = document.getElementById("client-id").value.trim();
const client_key = document.getElementById("app-secret").value.trim();
const site_type = document.getElementById("site-select").value;
const idElement = document.getElementById("sharepoint-id");

// 定义站点的API Endpoint
const GATEWAYS = {
"onedrive_go": "https://graph.microsoft.com/v1.0/sites/",
"onedrive_cn": "https://microsoftgraph.chinacloudapi.cn/v1.0/sites/",
"onedrive_us": "https://graph.microsoft.us/v1.0/sites/",
"onedrive_de": "https://graph.microsoft.de/v1.0/sites/"
};

// 定义错误信息
const ERROR_MESSAGES = {
MISSING_CREDENTIALS: "请先填写客户端ID和应用机密",
MISSING_TOKENS: "请获取Token",
MISSING_URL: "请填写您的SharePoint URL",
NOT_SUPPORTED: "仅支持OneDrive相关API",
NOT_FOUND: "站点不存在",
BAD_REQUEST: "获取出现问题,请检查权限和站点URL,站点URL示例:https://demo.sharepoint.com/site/demo",
DEFAULT: "请求发生错误"
};

// 验证
if (!client_uid || !client_key) {
idElement.value = ERROR_MESSAGES.MISSING_CREDENTIALS;
return;
}
if (!access_token || !refresh_token) {
idElement.value = ERROR_MESSAGES.MISSING_TOKENS;
return;
}
if (!siteUrl) {
idElement.value = ERROR_MESSAGES.MISSING_URL;
return;
}
if (!site_type.includes("onedrive")) {
idElement.value = ERROR_MESSAGES.NOT_SUPPORTED;
return;
}
if (!GATEWAYS[site_type]) {
idElement.value = ERROR_MESSAGES.DEFAULT;
return;
}

// 获取ID
try {
const urlParts = siteUrl.replace("https://", "").split("/");
const site_hostname = urlParts[0];
const site_sub_path = urlParts[1];
const site_name = urlParts[2];
const site_path = site_sub_path + "/" +site_name;
const reqUrl = `${GATEWAYS[site_type]}${site_hostname}:/${site_path}`;
const headers = {
"Accept": "application/json",
"Content-Type": "application/json",
"Authorization": `Bearer ${access_token}`
};

fetch(reqUrl, {
method: "GET",
headers: headers
})
.then(async (res) => {
if (!res.ok) {
if (res.status === 404) {
idElement.value = ERROR_MESSAGES.NOT_FOUND;
return;
} else if (res.status === 400) {
idElement.value = ERROR_MESSAGES.BAD_REQUEST;
return;
} else {
idElement.value = `${ERROR_MESSAGES.DEFAULT} (HTTP ${res.status})`;
return;
}
}

try {
const result = await res.json();
if (result.id) {
idElement.value = result.id;
} else if (result.error) {
idElement.value = result.error.message || ERROR_MESSAGES.DEFAULT;
} else {
idElement.value = ERROR_MESSAGES.DEFAULT;
}
} catch (error) {
idElement.value = ERROR_MESSAGES.DEFAULT;
console.error("处理响应时出错:", error);
}
})
.catch((error) => {
idElement.value = ERROR_MESSAGES.BAD_REQUEST;
console.error("请求失败:", error);
});
} catch (error) {
idElement.value = ERROR_MESSAGES.BAD_REQUEST;
console.error("URL解析失败:", error);
}
}
//手动切换主题模式
function toggleTheme() {
const html = document.documentElement;
Expand Down