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SACH,UAAU,SAAQ,eAAkB,EAAa,KACvD,EAAK,IAAM,GAAG,EAAO,UAAU,EAAK,OAAO,EAAK,aACzC,EAAK,MAChB,EACA,kBAAM,CAAa,SACT,UAAU,SAAQ,eAAkB,EAAa,KACvD,EAAK,IAAM,GAAG,EAAO,UAAU,EAAK,OAAO,EAAK,aACzC,EAAK,MAChB,EACA,OAAO,GACI,IAAI,SAAQ,CAAC,EAAS,KAvClB,OAAO,IACtB,MAAM,EAAO,GAAG,EAAO,OAAO,EAAK,OAAO,EAAK,YACzC,UAAU,SAAQ,UACpB,MAAM,QAAe,IACrB,UACU,EAAO,OAAO,EACxB,CACA,MAAO,GACH,MAAM,KAAE,GAAS,EACjB,GAAa,MAAT,EAKA,YAJA,qBAA8D,cAAc,UAAU,GAAO,CAAC,EAAO,KACjG,EAAM,OAAO,MAAO,UACpB,EAAM,SAAS,OAAO,KAQ9B,MAJA,qBAA8D,cAAc,UAAU,GAAO,CAAC,EAAO,KACjG,EAAM,OAAO,MAAO,UACpB,EAAM,SAAS,QAAQ,IAErB,CACV,CACA,cACU,EAAO,OACjB,IACF,EAeM,CAAW,GACN,MAAK,KACN,GAAS,IAER,OAAO,IACR,EAAO,EAAM,GACf,IAIlB","file":"/npm/strapi-provider-ftp-upload@1.0.4/dist/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/strapi-provider-ftp-upload@1.0.4/dist/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","\"use strict\";\nconst Readable = require(\"stream\").Readable;\nconst ftpClient = require(\"basic-ftp\");\nconst TaskQueue = require(\"./task-queue\").default;\nconst taskQueue = new TaskQueue({ concurrency: 5, queueLengthLimit: -1 });\nlet sentryService = undefined;\ntry {\n    sentryService = strapi.plugin(\"sentry\").service(\"sentry\");\n}\ncatch (error) { }\nmodule.exports = {\n    init(config) {\n        const getConnection = async () => {\n            taskQueue.setConcurrency(config.connectionConcurrency || 5);\n            sentryService = config.useSentry ? sentryService : undefined;\n            const client = new ftpClient.Client();\n            await client.access({\n                host: config.host,\n                user: config.user,\n                port: config.port,\n                password: config.password,\n                secure: config.secure,\n            });\n            return client;\n        };\n        const stream2buffer = async (stream) => {\n            return new Promise((resolve, reject) => {\n                const _buf = [];\n                stream.on(\"data\", (chunk) => _buf.push(chunk));\n                stream.on(\"end\", () => resolve(Buffer.concat(_buf)));\n                stream.on(\"error\", (err) => reject(err));\n            });\n        };\n        const uploadStream = async (inputFile) => {\n            const file = { ...inputFile };\n            file.buffer = await stream2buffer(file.stream);\n            const path = `${config.path}${file.hash}${file.ext}`;\n            const client = await getConnection();\n            try {\n                const source = new Readable();\n                source._read = () => { };\n                source.push(file.buffer);\n                source.push(null);\n                await client.uploadFrom(source, path);\n            }\n            catch (error) {\n                sentryService === null || sentryService === void 0 ? void 0 : sentryService.sendError(error, (scope, sentryInstance) => {\n                    scope.setTag(\"ftp\", \"upload\");\n                    scope.setLevel(\"error\");\n                });\n                throw error;\n            }\n            finally {\n                await client.close();\n            }\n        };\n        const deleteFile = async (file) => {\n            const path = `${config.path}${file.hash}${file.ext}`;\n            await taskQueue.enqueue(async () => {\n                const client = await getConnection();\n                try {\n                    await client.remove(path);\n                }\n                catch (error) {\n                    const { code } = error;\n                    if (code === 550) {\n                        sentryService === null || sentryService === void 0 ? void 0 : sentryService.sendError(error, (scope, sentryInstance) => {\n                            scope.setTag(\"ftp\", \"delete\");\n                            scope.setLevel(\"info\");\n                        });\n                        return;\n                    }\n                    sentryService === null || sentryService === void 0 ? void 0 : sentryService.sendError(error, (scope, sentryInstance) => {\n                        scope.setTag(\"ftp\", \"delete\");\n                        scope.setLevel(\"error\");\n                    });\n                    throw error;\n                }\n                finally {\n                    await client.close();\n                }\n            });\n        };\n        return {\n            async upload(file) {\n                await taskQueue.enqueue(async () => await uploadStream(file));\n                file.url = `${config.baseUrl}${file.hash}${file.ext}`;\n                delete file.buffer;\n            },\n            async uploadStream(file) {\n                await taskQueue.enqueue(async () => await uploadStream(file));\n                file.url = `${config.baseUrl}${file.hash}${file.ext}`;\n                delete file.buffer;\n            },\n            delete(file) {\n                return new Promise((resolve, reject) => {\n                    deleteFile(file)\n                        .then(() => {\n                        resolve();\n                    })\n                        .catch((error) => {\n                        reject(error);\n                    });\n                });\n            },\n        };\n    },\n};\n"]}