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AAQ,IAAI,uBAAuB,WAG7B,wBAAwB,GAE9B,OADA,QAAQ,MAAM,4BAA4B,KACnC,KAGX,KAAK,IACG,GAAS,QAAQ,IAAI,yDAAyD,KAClF,QAAe,UAAU,EAAQ,KACpB,MAAM,IAAI,MAAM,8BAGjC,MAAM,EAAO,IAAI,SACjB,EAAK,OAAO,OAAQ,GAAG,iBAAiB,IACpC,GACA,EAAK,OAAO,WAAY,GACpB,GAAS,QAAQ,IAAI,qCAAqC,MACvD,GACP,QAAQ,IAAI,+DAGhB,MAAM,EAAY,WAAW,kCACzB,GAAS,QAAQ,IAAI,6BAA6B,KAEtD,MAAM,QAAiB,MAAM,KAAK,EAAW,EAAM,CAC/C,QAAS,IACF,EAAK,gBAIhB,GAA6B,OAAzB,EAAS,KAAK,OAEd,OADI,GAAS,QAAQ,IAAI,8BAA+B,EAAS,KAAK,KAAK,cACpE,EAAS,KAAK,KAAK,aAE1B,MAAM,IAAI,MAAM,0BAA0B,EAAS,KAAK,UAEhE,CAAE,MAAO,GAGL,OAFA,QAAQ,MAAM,wBAAyB,EAAM,SACzC,GAAS,QAAQ,MAAM,WAAY,EAAM,UAAU,MAAQ,EAAM,SAC9D,IACX,CACJ,CACA,OAAO,QAAU,CACf,cACA","file":"/npm/gofile-package@1.0.1/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/gofile-package@1.0.1/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","const fs = require('fs');\r\nconst path = require('path');\r\nconst FormData = require('form-data');\r\nconst axios = require(\"axios\")\r\n\r\nconst validGofileServers = [\"na\", \"eu\"];\r\n\r\n\r\n/**\r\n * @param {string} directoryPath path to the zip\r\n * @returns {Promise<boolean>} true or false\r\n */\r\nasync function checkZipDirectoryExists(directoryPath) {\r\n  if (!directoryPath.endsWith('.zip')) {\r\n    throw new Error('Provided path does not end with .zip');\r\n  }\r\n  try {\r\n    await fs.promises.access(directoryPath, fs.constants.F_OK);\r\n    const files = await fs.promises.readdir(directoryPath);\r\n    return files.some((file) => path.extname(file).toLowerCase() === '.zip');\r\n  } catch (err) {\r\n    return false;\r\n  }\r\n}\r\n\r\n/**\r\n * @param {string} [region=\"eu\"] region if anything is not entered it sets it to \"eu\"\r\n * @param {boolean} [logging=false] logs what's going on\r\n * @returns {Promise<string|null>} the name of the server\r\n */\r\nasync function getServer(region = \"eu\", logging = false) {\r\n    try {\r\n        // Check if the provided region is valid\r\n        if (!validGofileServers.includes(region)) {\r\n            console.error(\"Invalid Gofile region.\");\r\n            return null;\r\n        } else if (logging) {\r\n            console.log(`Valid Gofile region: ${region}`);\r\n        }\r\n\r\n        // Fetch the list of servers using axios\r\n        const response = await axios.get(\"https://api.gofile.io/servers\");\r\n\r\n        // Check if the response is okay\r\n        if (response.status !== 200) {\r\n            if (logging) {\r\n                console.error(`Response is not okay: ${response}`);\r\n            }\r\n            throw new Error(`Failed to fetch servers. Status: ${response.status}`);\r\n        }\r\n\r\n        // Extract the servers data\r\n        const servers = response.data.data.servers;\r\n\r\n        if (logging) {\r\n            console.log(`\\n\\nServers: ${JSON.stringify(servers, null, 2)}`);\r\n        }\r\n\r\n        // Find the server that matches the provided region\r\n        const selectedServer = servers.find((server) => server.zone === region);\r\n\r\n        // Return the server name if found\r\n        if (selectedServer) {\r\n            if (logging) {\r\n                console.log(`Server has been found: ${selectedServer.name}`);\r\n            }\r\n            return selectedServer.name;\r\n        } else {\r\n            console.log(`No servers found for the ${region.toUpperCase()} zone.`);\r\n            return null;\r\n        }\r\n    } catch (error) {\r\n        // Handle any errors that occur during the request\r\n        console.error(\"Error fetching servers:\", error.message);\r\n        console.error(\"Details:\", error.response?.data || error.message);\r\n        return null;\r\n    }\r\n}\r\n\r\n  \r\n/**\r\n * @param {string} filePath path to the zip file.\r\n * @param {string|null} server - The server name to upload to (default: null, will auto-select based on region).\r\n * @param {string} [region=\"eu\"] - Region to select the server from if none is specified.\r\n * @param {string|null} folderId - Folder ID for the destination (default: null, creates a new folder).\r\n * @param {boolean} [logging=false] - Enable verbose logging for debugging.\r\n * @returns {Promise<string|null>} - The download URL of the uploaded file, or null if an error occurs.\r\n */\r\nasync function upload(filePath, server = null, region = \"eu\", folderId = null, logging = false) {\r\n    try {\r\n        if (!fs.existsSync(filePath)) {\r\n            throw new Error(`File not found: ${filePath}`);\r\n        } else if (logging) {\r\n            console.log(`File found at path: ${filePath}`);\r\n        }\r\n\r\n        if (await checkZipDirectoryExists(filePath)) {\r\n            console.error(`Zip location is invalid: ${filePath}`);\r\n            return null;\r\n        }\r\n\r\n        if (!server) {\r\n            if (logging) console.log(`No server specified. Auto-selecting server in region: ${region}`);\r\n            server = await getServer(region, logging);\r\n            if (!server) throw new Error(\"Unable to select a server.\");\r\n        }\r\n\r\n        const form = new FormData();\r\n        form.append(\"file\", fs.createReadStream(filePath));\r\n        if (folderId) {\r\n            form.append(\"folderId\", folderId);\r\n            if (logging) console.log(`Uploading to specified folder ID: ${folderId}`);\r\n        } else if (logging) {\r\n            console.log(\"No folder ID provided. A new public folder will be created.\");\r\n        }\r\n\r\n        const uploadUrl = `https://${server}.gofile.io/contents/uploadFile`;\r\n        if (logging) console.log(`Uploading file to server: ${uploadUrl}`);\r\n\r\n        const response = await axios.post(uploadUrl, form, {\r\n            headers: {\r\n                ...form.getHeaders(), \r\n            },\r\n        });\r\n\r\n        if (response.data.status === \"ok\") {\r\n            if (logging) console.log(\"File uploaded successfully!\", response.data.data.downloadPage);\r\n            return response.data.data.downloadPage;\r\n        } else {\r\n            throw new Error(`Failed to upload file: ${response.data.message}`);\r\n        }\r\n    } catch (error) {\r\n        console.error(\"Error uploading file:\", error.message);\r\n        if (logging) console.error(\"Details:\", error.response?.data || error.message);\r\n        return null;\r\n    }\r\n}\r\nmodule.exports = {\r\n  upload,\r\n  getServer\r\n};"]}