001-drive-proxy-adapter #1
@@ -25,9 +25,8 @@
|
|||||||
*
|
*
|
||||||
* Structure:
|
* Structure:
|
||||||
* Section 1: Authentication (Service Account JWT)
|
* Section 1: Authentication (Service Account JWT)
|
||||||
* Section 2: Request Queue (FIFO)
|
* Section 2: Drive API Client
|
||||||
* Section 3: Drive API Client
|
* Section 3: Request Handling & Routing
|
||||||
* Section 4: Request Handling & Routing
|
|
||||||
*
|
*
|
||||||
* @module proxy
|
* @module proxy
|
||||||
*/
|
*/
|
||||||
@@ -104,58 +103,7 @@ async function getAccessTokenCached() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// =============================================================================
|
// =============================================================================
|
||||||
// Section 2: Request Queue (FIFO)
|
// Section 2: Drive API Client
|
||||||
// =============================================================================
|
|
||||||
|
|
||||||
/**
|
|
||||||
* FIFO Queue for sequential request processing
|
|
||||||
* Prevents concurrent Drive API operations per specification
|
|
||||||
*/
|
|
||||||
class RequestQueue {
|
|
||||||
constructor() {
|
|
||||||
this.queue = [];
|
|
||||||
this.processing = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
async enqueue(handler) {
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
this.queue.push({ handler, resolve, reject });
|
|
||||||
if (!this.processing) this._processNext();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
async _processNext() {
|
|
||||||
if (this.queue.length === 0) {
|
|
||||||
this.processing = false;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.processing = true;
|
|
||||||
const { handler, resolve, reject } = this.queue.shift();
|
|
||||||
|
|
||||||
try {
|
|
||||||
resolve(await handler());
|
|
||||||
} catch (error) {
|
|
||||||
reject(error);
|
|
||||||
} finally {
|
|
||||||
this._processNext();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
get length() {
|
|
||||||
return this.queue.length;
|
|
||||||
}
|
|
||||||
|
|
||||||
get isProcessing() {
|
|
||||||
return this.processing;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Singleton instance
|
|
||||||
const requestQueue = new RequestQueue();
|
|
||||||
|
|
||||||
// =============================================================================
|
|
||||||
// Section 3: Drive API Client
|
|
||||||
// =============================================================================
|
// =============================================================================
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -214,11 +162,11 @@ async function queryDocuments(options = {}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// =============================================================================
|
// =============================================================================
|
||||||
// Section 4: Request Handling & Routing
|
// Section 3: Request Handling & Routing
|
||||||
// =============================================================================
|
// =============================================================================
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle sitemap generation request (wrapped in FIFO queue)
|
* Handle sitemap generation request
|
||||||
*/
|
*/
|
||||||
async function handleSitemapRequest(res, requestId) {
|
async function handleSitemapRequest(res, requestId) {
|
||||||
try {
|
try {
|
||||||
@@ -275,9 +223,9 @@ async function handleSitemapRequest(res, requestId) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle sitemap route with FIFO queue (sequential processing)
|
// Handle sitemap route
|
||||||
if (routeResult.route === "sitemap") {
|
if (routeResult.route === "sitemap") {
|
||||||
await requestQueue.enqueue(() => handleSitemapRequest(res, requestId));
|
await handleSitemapRequest(res, requestId);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
Reference in New Issue
Block a user