Merge pull request #4 from xiaoman1221/main

增加获取SharePoint站点ID功能,更改中国区EndPoint
This commit is contained in:
Pikachu Ren 2025-06-15 09:56:43 +08:00 committed by GitHub
commit e2a5d828d9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 136 additions and 5 deletions

View File

@ -8,5 +8,7 @@
</content> </content>
<orderEntry type="inheritedJdk" /> <orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" /> <orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="bootstrap" level="application" />
<orderEntry type="library" name="sweetalert2" level="application" />
</component> </component>
</module> </module>

17
.idea/workspace.xml generated
View File

@ -30,6 +30,18 @@
<component name="Git.Settings"> <component name="Git.Settings">
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" /> <option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
</component> </component>
<component name="GitHubPullRequestSearchHistory"><![CDATA[{
"lastFilter": {
"state": "OPEN",
"assignee": "xiaoman1221"
}
}]]></component>
<component name="GithubPullRequestsUISettings"><![CDATA[{
"selectedUrlAndAccountId": {
"url": "git@github.com:xiaoman1221/cf-worker-api.git",
"accountId": "dc84280e-17eb-471f-bdb9-c542ed6bcde0"
}
}]]></component>
<component name="ProblemsViewState"> <component name="ProblemsViewState">
<option name="selectedTabId" value="CurrentFile" /> <option name="selectedTabId" value="CurrentFile" />
</component> </component>
@ -54,7 +66,7 @@
"node.js.selected.package.tslint": "(autodetect)", "node.js.selected.package.tslint": "(autodetect)",
"nodejs_package_manager_path": "npm", "nodejs_package_manager_path": "npm",
"settings.editor.selected.configurable": "preferences.language.and.region", "settings.editor.selected.configurable": "preferences.language.and.region",
"ts.external.directory.path": "C:\\Users\\pikachuren\\AppData\\Local\\Programs\\WebStorm\\plugins\\javascript-plugin\\jsLanguageServicesImpl\\external", "ts.external.directory.path": "/Users/xiaoman1221/Applications/WebStorm.app/Contents/plugins/javascript-plugin/jsLanguageServicesImpl/external",
"vue.rearranger.settings.migration": "true" "vue.rearranger.settings.migration": "true"
} }
}]]></component> }]]></component>
@ -84,7 +96,8 @@
<updated>1749696640494</updated> <updated>1749696640494</updated>
<workItem from="1749696641557" duration="119000" /> <workItem from="1749696641557" duration="119000" />
<workItem from="1749696773818" duration="18000" /> <workItem from="1749696773818" duration="18000" />
<workItem from="1749696801474" duration="56160000" /> <workItem from="1749696801474" duration="20247000" />
<workItem from="1749729820615" duration="1140000" />
</task> </task>
<task id="LOCAL-00001" summary="fin onedrive official token"> <task id="LOCAL-00001" summary="fin onedrive official token">
<option name="closed" value="true" /> <option name="closed" value="true" />

View File

@ -1,5 +1,5 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="zh-CN" data-theme="light"> <html lang="zh-CN" data-theme="light" xmlns="http://www.w3.org/1999/html">
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
@ -155,7 +155,17 @@
<label for="refresh-token" class="form-label">刷新秘钥</label> <label for="refresh-token" class="form-label">刷新秘钥</label>
<textarea id="refresh-token" class="form-control" rows="3" readonly onclick="autoCopy(this)"></textarea> <textarea id="refresh-token" class="form-control" rows="3" readonly onclick="autoCopy(this)"></textarea>
</div> </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"> <div class="text-muted text-center">
<p style="text-align:center"> <p style="text-align:center">
本工具所有信息只以Cookie形式存储于浏览器本地<br> 本工具所有信息只以Cookie形式存储于浏览器本地<br>
@ -165,7 +175,6 @@
</p> </p>
</div> </div>
</div> </div>
</div>
<script> <script>
let intervalId; let intervalId;
@ -364,6 +373,113 @@
} }
} }
// 获取站点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() { function toggleTheme() {
const html = document.documentElement; const html = document.documentElement;