response.headers.add('X-Script-Version', 'runtime-thread-1.0')

function stop() {
    var script = payload.get().query['path[]']
    if (script[0] == '*') {
        runtime.thread.stopAll()
        return ``
    }
    for (var i = 0; i < script.length; i++) {
        runtime.thread.stop(script[i])
    }
}

function list() {
    return JSON.stringify(runtime.thread.list())
}

function main() {
    // 验证用户权限
    'use api/user/acl/excerpt.js'

    switch (payload.get().method) {
        case 'GET':
            return list()
        case 'DELETE':
            return stop()
        default:
            response.status.notFound()
            return `404 page not found`
    }
}