kopia lustrzana https://github.com/transitive-bullshit/chatgpt-api
fix: avoid find calls
rodzic
809a5d4484
commit
b475ea87a1
27
src/task.ts
27
src/task.ts
|
@ -159,26 +159,29 @@ export abstract class BaseTask<
|
||||||
): this {
|
): this {
|
||||||
const hooks = hookType === 'before' ? this._preHooks : this._postHooks
|
const hooks = hookType === 'before' ? this._preHooks : this._postHooks
|
||||||
|
|
||||||
|
let found = false
|
||||||
if (typeof hookOrName === 'string') {
|
if (typeof hookOrName === 'string') {
|
||||||
const hookObj = hooks.find((h) => h.name === hookOrName)
|
for (const hookObj of hooks) {
|
||||||
if (!hookObj) {
|
if (hookObj.name === hookOrName) {
|
||||||
throw new Error(
|
found = true
|
||||||
`Could not find a ${hookType}-call hook named "${hookOrName}" to change its priority`
|
hookObj.priority = newPriority
|
||||||
)
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for (const hookObj of hooks) {
|
||||||
|
if (hookObj.hook === hookOrName) {
|
||||||
|
found = true
|
||||||
|
hookObj.priority = newPriority
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
hookObj.priority = newPriority
|
if (!found) {
|
||||||
} else {
|
|
||||||
const hookObj = hooks.find((h) => h.hook === hookOrName)
|
|
||||||
if (!hookObj) {
|
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`Could not find the provided ${hookType}-call hook to change its priority`
|
`Could not find the provided ${hookType}-call hook to change its priority`
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
hookObj.priority = newPriority
|
|
||||||
}
|
|
||||||
|
|
||||||
hooks.sort((a, b) => b.priority - a.priority)
|
hooks.sort((a, b) => b.priority - a.priority)
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
Ładowanie…
Reference in New Issue