mirror of
https://github.com/wukko/cobalt.git
synced 2024-11-15 04:39:58 +00:00
api/stream: use Map for storing info about internal streams
This commit is contained in:
parent
57c9836f56
commit
15a90e9b11
1 changed files with 7 additions and 7 deletions
|
@ -22,7 +22,7 @@ streamCache.on("expired", (key) => {
|
|||
streamCache.del(key);
|
||||
})
|
||||
|
||||
const internalStreamCache = {};
|
||||
const internalStreamCache = new Map();
|
||||
const hmacSalt = randomBytes(64).toString('hex');
|
||||
|
||||
export function createStream(obj) {
|
||||
|
@ -71,7 +71,7 @@ export function createStream(obj) {
|
|||
}
|
||||
|
||||
export function getInternalStream(id) {
|
||||
return internalStreamCache[id];
|
||||
return internalStreamCache.get(id);
|
||||
}
|
||||
|
||||
export function createInternalStream(url, obj = {}) {
|
||||
|
@ -95,13 +95,13 @@ export function createInternalStream(url, obj = {}) {
|
|||
headers = new Map(Object.entries(obj.headers));
|
||||
}
|
||||
|
||||
internalStreamCache[streamID] = {
|
||||
internalStreamCache.set(streamID, {
|
||||
url,
|
||||
service: obj.service,
|
||||
headers,
|
||||
controller,
|
||||
dispatcher
|
||||
};
|
||||
});
|
||||
|
||||
let streamLink = new URL('/itunnel', `http://127.0.0.1:${env.apiPort}`);
|
||||
streamLink.searchParams.set('id', streamID);
|
||||
|
@ -124,9 +124,9 @@ export function destroyInternalStream(url) {
|
|||
|
||||
const id = url.searchParams.get('id');
|
||||
|
||||
if (internalStreamCache[id]) {
|
||||
closeRequest(internalStreamCache[id].controller);
|
||||
delete internalStreamCache[id];
|
||||
if (internalStreamCache.has(id)) {
|
||||
closeRequest(getInternalStream(id)?.controller);
|
||||
internalStreamCache.delete(id);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue