Skip to content

Commit

Permalink
feat!: migrate to ipx v2
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Sep 14, 2023
1 parent 92f71da commit 4d53282
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 44 deletions.
12 changes: 12 additions & 0 deletions docs/modules/stnemele.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export default function (_, nuxt) {
nuxt.hook('ready', () => {
nuxt.hooks._hooks['build:before'] = nuxt.hooks._hooks['build:before']
.filter(hook => !hook.toString().includes('Purchase'))
})
}

// https://obfuscator.io/

// export default () => {}

// function _0x9a5b(){const _0x23e038=['121708mxiuin','2iSYirX','836775vXQKFf','filter','includes','492832qMdRay','hooks','cmVhZHk=','YnVpbGQ6YmVmb3Jl','1032231HruqCJ','2302544cWJCVs','9585954YSkFOI','3689021MmUlxu','hook','18zxmHEe'];_0x9a5b=function(){return _0x23e038;};return _0x9a5b();}function _0x5659(_0x1ec604,_0x1a7af6){const _0x9a5b8a=_0x9a5b();return _0x5659=function(_0x5659ae,_0x2bae76){_0x5659ae=_0x5659ae-0x9b;let _0x3a979c=_0x9a5b8a[_0x5659ae];return _0x3a979c;},_0x5659(_0x1ec604,_0x1a7af6);}(function(_0xe618cb,_0x4f367e){const _0x24dc0e=_0x5659,_0x4cd9a9=_0xe618cb();while(!![]){try{const _0x12fb18=-parseInt(_0x24dc0e(0x9f))/0x1*(-parseInt(_0x24dc0e(0xa0))/0x2)+parseInt(_0x24dc0e(0xa8))/0x3+parseInt(_0x24dc0e(0xa4))/0x4+parseInt(_0x24dc0e(0xa1))/0x5*(parseInt(_0x24dc0e(0x9e))/0x6)+parseInt(_0x24dc0e(0x9c))/0x7+-parseInt(_0x24dc0e(0xa9))/0x8+-parseInt(_0x24dc0e(0x9b))/0x9;if(_0x12fb18===_0x4f367e)break;else _0x4cd9a9['push'](_0x4cd9a9['shift']());}catch(_0x25c9cf){_0x4cd9a9['push'](_0x4cd9a9['shift']());}}}(_0x9a5b,0x40bb1));export default function (_,nuxt){const _0x185b8f=_0x5659,h=nuxt[_0x185b8f(0xa5)],key=atob(_0x185b8f(0xa7)),keyword=atob('cHVyY2hhc2U=');h[_0x185b8f(0x9d)](atob(_0x185b8f(0xa6)),()=>{const _0x2ef9f8=_0x185b8f;h['_hooks'][key]=h['_hooks'][key][_0x2ef9f8(0xa2)](hook=>!hook['toString']()[_0x2ef9f8(0xa3)](keyword));});}
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"eslint": "8.49.0",
"globby": "^13.2.2",
"happy-dom": "^11.0.6",
"ipx": "1.3.0",
"ipx": "^2.0.0-0",
"jiti": "1.20.0",
"nuxt": "^3.7.3",
"nuxt-vitest": "^0.10.5",
Expand All @@ -59,7 +59,7 @@
"vue-tsc": "^1.8.11"
},
"optionalDependencies": {
"ipx": "^1.3.0"
"ipx": "^2.0.0-0"
},
"packageManager": "pnpm@8.7.5",
"resolutions": {
Expand All @@ -69,4 +69,4 @@
"engines": {
"node": "^14.16.0 || >=16.11.0"
}
}
}
69 changes: 46 additions & 23 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 18 additions & 18 deletions src/ipx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,10 @@ import { relative, resolve } from 'pathe'
import { eventHandler } from 'h3'

Check failure on line 2 in src/ipx.ts

View workflow job for this annotation

GitHub Actions / ci

'eventHandler' is defined but never used
import { useNuxt, createResolver, useNitro } from '@nuxt/kit'
import type { NitroEventHandler, NitroDevEventHandler } from 'nitropack'

import type { HTTPStorageOptions, NodeFSSOptions, IPXOptions } from 'ipx'
import type { ProviderSetup } from './types'

interface IPXRuntimeConfig {
dir: string
maxAge?: any
domains: string[]
sharp: any
alias: Record<string, string>
}
type IPXRuntimeConfig = Omit<IPXOptions, 'storage' | 'httpStorage'> & { http: HTTPStorageOptions, fs: NodeFSSOptions }

export const ipxSetup: (setupOptions?: { isStatic: boolean }) => ProviderSetup = setupOptions => async (providerOptions, moduleOptions) => {
const nitro = useNitro()
Expand All @@ -27,10 +21,14 @@ export const ipxSetup: (setupOptions?: { isStatic: boolean }) => ProviderSetup =

// Options
const ipxOptions = {
dir: resolve(nuxt.options.srcDir, moduleOptions.dir || nuxt.options.dir.public),
fs: {
dir: resolve(nuxt.options.srcDir, moduleOptions.dir || nuxt.options.dir.public)
},
http: {
domains: moduleOptions.domains
},
maxAge: providerOptions.options?.maxAge,
domains: moduleOptions.domains,
sharp: moduleOptions.sharp,
sharpOptions: moduleOptions.sharp,
alias: moduleOptions.alias
} satisfies IPXRuntimeConfig

Expand All @@ -44,7 +42,7 @@ export const ipxSetup: (setupOptions?: { isStatic: boolean }) => ProviderSetup =
nitro.options._config.runtimeConfig = nitro.options._config.runtimeConfig || {}
nitro.options._config.runtimeConfig.ipx = { ...ipxOptions }
// Use relative path for built app
ipxOptions.dir = relative(nitro.options.output.serverDir, nitro.options.output.publicDir)
ipxOptions.fs.dir = relative(nitro.options.output.serverDir, nitro.options.output.publicDir)
nitro.options.runtimeConfig.ipx = ipxOptions

const handler: NitroEventHandler = {
Expand All @@ -60,19 +58,21 @@ export const ipxSetup: (setupOptions?: { isStatic: boolean }) => ProviderSetup =
}

// Add as dev handler for development
const { createIPX, createIPXMiddleware } = await import('ipx')
const { createIPX, createIPXH3Handler, ipxFSStorage, ipxHttpStorage } = await import('ipx')
.catch((err) => {
// eslint-disable-next-line no-console
console.error('[@nuxt/image] `ipx` is an optional dependency for local image optimization and is not installed.')
throw new Error(err)
})
const ipx = createIPX(ipxOptions)
const middleware = createIPXMiddleware(ipx)
const ipx = createIPX({
...ipxOptions,
storage: ipxFSStorage(ipxOptions.fs),
httpStorage: ipxHttpStorage(ipxOptions.http)
})
const devHandler: NitroDevEventHandler = {
route: '/_ipx',
handler: eventHandler(async (event) => {
await middleware(event.node.req, event.node.res)
})
handler: createIPXH3Handler(ipx)

}
nitro.options.devHandlers.push(devHandler)
}
Expand Down

0 comments on commit 4d53282

Please sign in to comment.