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EAAM,MAAK,GAAiB,QAAZ,EAAE,QAAiB,OAAa,QAAQ,IAC/E,EAAc,YAA2D,IAA/C,EAAM,MAAK,GAAiB,YAAZ,EAAE,QAAqB,OAAa,QAAQ,IAC5F,MAAO,CACN,IAAkB,MAAb,GAAoB,EAAW,EACpC,SAAwB,MAAb,GAAoB,EAAW,EAAe,EAAW,EACpE,KAAM,EAAa,EAAM,KACzB,OAAQ,CACP,IAAK,EAAW,EAAI,EAAI,EACxB,OAAQ,EAAc,EAAI,EAAI,GAGjC,CACD,gBAEe,aACN,MAAO,kBACT,SAAS,WAAa,OAAO,KAAO","file":"/npm/@furries-suck/is-cub@1.0.8/src/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/@furries-suck/is-cub@1.0.8/src/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","// https://stackoverflow.com/a/51771139\nimport \"./disable_warn.js\";\nimport TeachableMachine from \"@sashido/teachablemachine-node\";\nimport { fileTypeFromBuffer } from \"file-type\";\nimport debugFunc from \"debug\";\nconst debug = debugFunc(\"is-cub\");\nimport getFrames from \"./get-frames.js\";\nimport { existsSync, readFileSync } from \"fs\";\nimport { basename, dirname } from \"path\";\nimport fetch from \"node-fetch\";\nimport { fileURLToPath } from \"url\";\nconst model = new TeachableMachine({\n\tmodelUrl: \"https://teachablemachine.withgoogle.com/models/easeCRv0Q/\"\n});\nconst userAgent = `Is-Cub/${JSON.parse(readFileSync(`${dirname(fileURLToPath(import.meta.url))}/../package.json`).toString()).version} (https://github.com/DonovanDMC/Is-Cub)`;\n\nlet i = 0;\nasync function awaitReady(time = 1000) {\n\ti++;\n\tif(!model) {\n\t\tdebug(\"(try %d) Model is not ready, retrying in %d ms...\", i, time);\n\t\tawait new Promise(resolve => setTimeout(resolve, time));\n\t\treturn awaitReady(time);\n\t} else {\n\t\tlet ready;\n\t\ttry {\n\t\t\tawait model.checkModel();\n\t\t\tready = true;\n\t\t} catch {\n\t\t\tready = false;\n\t\t}\n\n\t\tif(!ready) {\n\t\t\tdebug(\"(try %d) Model is not ready, retrying in %d ms...\", i, time);\n\t\t\tawait new Promise(resolve => setTimeout(resolve, time));\n\t\t\treturn awaitReady(time);\n\t\t}\n\t}\n}\n\n/**\n * @typedef SingleResponse - singular response\n * @prop {boolean} cub - if the provided image if cub\n * @prop {number} sureness - how sure we are that the image is or isn't cub\n * @prop {(Buffer | null)} file - the file buffer, if keepFrames is true\n * @prop {object} scores - the individual scores\n * @prop {number} scores.cub\n * @prop {number} scores.notCub \n */\n\n/**\n * @typedef IndividualAnimatedResponse\n * @prop {number} frame - the frame this response was generated from\n * @prop {boolean} cub - if the provided image if cub\n * @prop {number} sureness - how sure we are that the image is or isn't cub\n * @prop {(Buffer | null)} file - the file buffer, if keepFrames is true\n * @prop {object} scores - the individual scores\n * @prop {number} scores.cub\n * @prop {number} scores.notCub \n */\n\n/**\n * @typedef AnimatedResponse - Animated or video response\n * @prop {boolean} cub - if the provided image if cub\n * @prop {number} sureness - how sure we are that the image is or isn't cub\n * @prop {(Buffer | null)} file - the file buffer, if keepFrames is true\n * @prop {object} scores - the individual scores\n * @prop {number} scores.cub\n * @prop {number} scores.notCub \n * @prop {Array<IndividualAnimatedResponse>} individual - the frame specific scores\n * @prop {object} overall - frames sorted into which category they ended up in\n * @prop {Array<IndividualAnimatedResponse>} overall.cub\n * @prop {Array<IndividualAnimatedResponse>} overall.notCub\n */\n\nfunction condenseMulti(val, keepFrames) {\n\tconst totalCubScore = parseFloat((val.reduce((a,b) => a + b.scores.cub, 0) / val.length).toFixed(2));\n\tconst totalNotCubScore = parseFloat((val.reduce((a,b) => a + b.scores.notCub, 0) / val.length).toFixed(2));\n\treturn {\n\t\tcub: totalCubScore === 100 || totalCubScore > totalNotCubScore,\n\t\tsureness: (totalCubScore === 100 || totalCubScore > totalNotCubScore) ? totalCubScore : totalNotCubScore,\n\t\tfile: keepFrames && (totalCubScore === 100 || totalCubScore > totalNotCubScore) ? val.sort((a,b) => a.sureness - b.sureness)[0].file || null : null,\n\t\tscores: {\n\t\t\tcub: totalCubScore,\n\t\t\tnotCub: totalNotCubScore\n\t\t},\n\t\tindividual: val,\n\t\toverall: {\n\t\t\tcub: val.filter(r => r.cub),\n\t\t\tnotCub: val.filter(r => !r.cub)\n\t\t}\n\t}\n}\n\n/**\n * \n * @param {string} input - the file or url to process\n * @param {number} [sampleSize=5] - the sample size for video files\n * @param {boolean} [keepFrames=false] - if used frames should be returned\n * @returns {Promise<SingleResponse | AnimatedResponse>} \n */\nasync function isCub(input, sampleSize = 5, keepFrames = false) {\n\tif(!input) throw new Error(\"Input Is Required.\");\n\tlet buf;\n\tif(Buffer.isBuffer(input)) buf = input;\n\telse if(/^[a-zA-Z0-9+/]={0,3}$/.test(input)) buf = Buffer.from(input.split(\",\")[1], \"base64\");\n\telse if(/^[a-zA-Z0-9-_]={0,3}$/.test(input)) buf = Buffer.from(input.split(\",\")[1], \"base64url\");\n\telse if(/https?:\\/\\/(www\\.)?[-a-zA-Z0-9@:%._\\+~#=]{1,256}\\.[a-zA-Z0-9()]{1,6}\\b([-a-zA-Z0-9()@:%_\\+.~#?&//=]*)/.test(input)) {\n\t\tconst get = await fetch(input, {\n\t\t\tmethod: \"GET\",\n\t\t\theaders: {\n\t\t\t\t\"User-Agent\": userAgent\n\t\t\t}\n\t\t});\n\t\tif(get.status < 200 || get.status > 399) throw new Error(`Failed to fetch input \"${input}\"`);\n\t\telse buf = await get.arrayBuffer().then(b => Buffer.from(b));\n\t} else {\n\t\tif(!existsSync(input)) throw new Error(`File Input \"${input}\" Does Not Exist.`);\n\t\tbuf = readFileSync(input);\n\t}\n\tif(!buf) throw new Error(`Failed To Retrieve Anything From Input \"${input}\"`);\n\tawait awaitReady();\n\tconst { mime } = await fileTypeFromBuffer(buf);\n\tif(mime && mime.startsWith(\"video/\") || mime === \"image/gif\") {\n\t\tconst { frames, done } = await getFrames(input, sampleSize);\n\t\tconst all = await Promise.all(frames.map(async(f) => ({ frame: Number(basename(f).split(\".\")[0].split(\"_\")[1]), ...(await isCub(f, sampleSize, keepFrames)) })));\n\t\tdone();\n\t\treturn condenseMulti(all, keepFrames);\n\t} else {\n\t\tconst check = await model.classify({\n\t\t\timageUrl: `data:${mime};base64,${buf.toString(\"base64\")}`\n\t\t}).catch(err => err);\n\t\tif(!Array.isArray(check)) throw new Error(`Recieved non-array response: ${typeof check === \"object\" ? JSON.stringify(check) : check}`);\n\t\tconst cubScore = parseFloat((check.find(c => c.class === \"Cub\").score * 100).toFixed(2));\n\t\tconst notCubScore = parseFloat((check.find(c => c.class === \"Not Cub\").score * 100).toFixed(2));\n\t\treturn {\n\t\t\tcub: cubScore === 100 || cubScore > notCubScore,\n\t\t\tsureness: (cubScore === 100 || cubScore > notCubScore) ? cubScore : notCubScore,\n\t\t\tfile: keepFrames ? buf : null,\n\t\t\tscores: {\n\t\t\t\tcub: cubScore < 1 ? 0 : cubScore,\n\t\t\t\tnotCub: notCubScore < 1 ? 0 : notCubScore\n\t\t\t}\n\t\t}\n\t}\n}\n\nexport default isCub;\nexport { isCub, getFrames };\nexport function getModel() { return model; }\n"]}