function doGet(e) { try { const targetUrl = getTargetUrl_(e); if (!isAllowedUrl_(targetUrl)) { throw new Error("Only siatube.com is allowed"); }a const response = UrlFetchApp.fetch(targetUrl, { method: "get", muteHttpExceptions: true, followRedirects: true, }); const contentType = response.getHeaders()["Content-Type"] || response.getHeaders()["content-type"] || "text/plain"; return ContentService .createTextOutput(response.getContentText()) .setMimeType(getMimeType_(contentType)); } catch (error) { return ContentService .createTextOutput(JSON.stringify({ ok: false, error: error.message, })) .setMimeType(ContentService.MimeType.JSON); } } function getTargetUrl_(e) { const queryString = e && e.queryString ? String(e.queryString) : ""; if (queryString.indexOf("url=") !== 0) { throw new Error("url is required"); } let targetUrl = queryString.substring(4); if (!targetUrl) { throw new Error("url is required"); } if ( targetUrl.indexOf("https://") !== 0 && targetUrl.indexOf("http://") !== 0 ) { try { const decoded = decodeURIComponent(targetUrl); if ( decoded.indexOf("https://") === 0 || decoded.indexOf("http://") === 0 ) { targetUrl = decoded; } } catch (_) {} } return targetUrl; } function isAllowedUrl_(targetUrl) { return ( targetUrl.indexOf("https://siatube.com/") === 0 || targetUrl === "https://siatube.com" ); } function getMimeType_(contentType) { const type = String(contentType).toLowerCase(); if (type.indexOf("application/json") !== -1) { return ContentService.MimeType.JSON; } if ( type.indexOf("application/javascript") !== -1 || type.indexOf("text/javascript") !== -1 ) { return ContentService.MimeType.JAVASCRIPT; } if (type.indexOf("text/csv") !== -1) { return ContentService.MimeType.CSV; } if ( type.indexOf("application/xml") !== -1 || type.indexOf("text/xml") !== -1 ) { return ContentService.MimeType.XML; } return ContentService.MimeType.TEXT; }