• R/O
  • HTTP
  • SSH
  • HTTPS

コミット

タグ
未設定

よく使われているワード(クリックで追加)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Fast OneDrive Index,OneDrive 秒级列表程序


コミットメタ情報

リビジョンe7fb7a46418a93eb2c498644d1987a9de5d0248f (tree)
日時2020-05-28 01:42:39
作者LOGI <vcheckzen@outl...>
コミッターGitHub

ログメッセージ

Update index.js

変更サマリ

差分

--- a/back-end-cf/index.js
+++ b/back-end-cf/index.js
@@ -178,183 +178,3 @@ async function fetchFiles(path, fileName, passwd) {
178178 }
179179 }
180180 }
181-/**
182- * IS_CN: 如果为世纪互联版本,请将 0 改为 1
183- * EXPOSE_PATH:暴露路径,如全盘展示请留空,否则按 '/媒体/音乐' 的格式填写
184- * ONEDRIVE_REFRESHTOKEN: refresh_token
185- */
186-const IS_CN = 0
187-const EXPOSE_PATH = ""
188-const ONEDRIVE_REFRESHTOKEN = ""
189-const PASSWD_FILENAME = '.password'
190-
191-async function handleRequest(request) {
192- let querySplited, requestPath
193- let queryString = decodeURIComponent(request.url.split('?')[1])
194- if (queryString) querySplited = queryString.split('=')
195- if (querySplited && querySplited[0] === 'file') {
196- const file = querySplited[1]
197- const fileName = file.split('/').pop()
198- if (fileName === PASSWD_FILENAME) return
199- requestPath = file.replace('/' + fileName, '')
200- const url = await fetchFiles(requestPath, fileName)
201- return Response.redirect(url, 302)
202- } else {
203- const { headers } = request
204- const contentType = headers.get('content-type')
205- let body = {}
206- if (contentType && contentType.includes('form')) {
207- const formData = await request.formData()
208- for (let entry of formData.entries()) {
209- body[entry[0]] = entry[1]
210- }
211- }
212- requestPath = body ? body['?path'] : ''
213- const files = await fetchFiles(requestPath, null, body.passwd)
214- return new Response(files, {
215- headers: {
216- 'content-type': 'application/json; charset=utf-8',
217- 'Access-Control-Allow-Origin': '*'
218- }
219- })
220- }
221-}
222-
223-addEventListener('fetch', event => {
224- return event.respondWith(handleRequest(event.request))
225-})
226-
227-
228-const clientId = [
229- '4da3e7f2-bf6d-467c-aaf0-578078f0bf7c',
230- '04c3ca0b-8d07-4773-85ad-98b037d25631'
231-
232-]
233-const clientSecret = [
234- '7/+ykq2xkfx:.DWjacuIRojIaaWL0QI6',
235- 'h8@B7kFVOmj0+8HKBWeNTgl@pU/z4yLB'
236-]
237-
238-const oauthHost = [
239- 'https://login.microsoftonline.com',
240- 'https://login.partner.microsoftonline.cn'
241-]
242-
243-const apiHost = [
244- 'https://graph.microsoft.com',
245- 'https://microsoftgraph.chinacloudapi.cn'
246-]
247-
248-const OAUTH = {
249- 'redirectUri': 'https://scfonedrive.github.io',
250- 'refreshToken': ONEDRIVE_REFRESHTOKEN,
251- 'clientId': clientId[IS_CN],
252- 'clientSecret': clientSecret[IS_CN],
253- 'oauthUrl': oauthHost[IS_CN] + '/common/oauth2/v2.0/',
254- 'apiUrl': apiHost[IS_CN] + '/v1.0/me/drive/root',
255- 'scope': apiHost[IS_CN] + '/Files.ReadWrite.All offline_access'
256-}
257-
258-async function gatherResponse(response) {
259- const { headers } = response
260- const contentType = headers.get('content-type')
261- if (contentType.includes('application/json')) {
262- return await response.json()
263- } else if (contentType.includes('application/text')) {
264- return await response.text()
265- } else if (contentType.includes('text/html')) {
266- return await response.text()
267- } else {
268- return await response.text()
269- }
270-}
271-
272-async function getContent(url) {
273- const response = await fetch(url)
274- const result = await gatherResponse(response)
275- return result
276-}
277-
278-async function getContentWithHeaders(url, headers) {
279- const response = await fetch(url, { headers: headers })
280- const result = await gatherResponse(response)
281- return result
282-}
283-
284-async function fetchFormData(url, data) {
285- const formdata = new FormData()
286- for (const key in data) {
287- if (data.hasOwnProperty(key)) {
288- formdata.append(key, data[key])
289- }
290- }
291- const requestOptions = {
292- method: 'POST',
293- body: formdata
294- }
295- const response = await fetch(url, requestOptions)
296- const result = await gatherResponse(response)
297- return result
298-}
299-
300-async function fetchAccessToken() {
301- url = OAUTH['oauthUrl'] + 'token'
302- data = {
303- 'client_id': OAUTH['clientId'],
304- 'client_secret': OAUTH['clientSecret'],
305- 'grant_type': 'refresh_token',
306- 'requested_token_use': 'on_behalf_of',
307- 'refresh_token': OAUTH['refreshToken']
308- }
309- const result = await fetchFormData(url, data)
310- return result.access_token
311-}
312-
313-async function fetchFiles(path, fileName, passwd) {
314- if (!path || path === '/') path = ''
315- path = (path || EXPOSE_PATH) ? ':' + EXPOSE_PATH + path : ''
316-
317- const accessToken = await fetchAccessToken()
318- const uri = OAUTH.apiUrl + encodeURI(path)
319- + '?expand=children(select=name,size,parentReference,lastModifiedDateTime,@microsoft.graph.downloadUrl)'
320- const body = await getContentWithHeaders(uri, { Authorization: 'Bearer ' + accessToken })
321- if (fileName) {
322- let thisFile = null
323- body.children.forEach(file => {
324- if (file.name === decodeURIComponent(fileName)) {
325- thisFile = file['@microsoft.graph.downloadUrl']
326- return
327- }
328- })
329- return thisFile
330- } else {
331- let files = []
332- let encrypted = false
333- for (let i = 0; i < body.children.length; i++) {
334- const file = body.children[i]
335- if (file.name === PASSWD_FILENAME) {
336- const PASSWD = await getContent(file['@microsoft.graph.downloadUrl'])
337- if (PASSWD !== passwd) {
338- encrypted = true
339- break
340- } else {
341- continue
342- }
343- }
344- files.push({
345- name: file.name,
346- size: file.size,
347- time: file.lastModifiedDateTime,
348- url: file['@microsoft.graph.downloadUrl']
349- })
350- }
351- let parent = body.children.length ? body.children[0].parentReference.path : body.parentReference.path
352- parent = parent.split(':').pop().replace(EXPOSE_PATH, '') || '/'
353- parent = decodeURIComponent(parent)
354- if (encrypted) {
355- return JSON.stringify({ parent: parent, files: [], encrypted: true })
356- } else {
357- return JSON.stringify({ parent: parent, files: files })
358- }
359- }
360-}