Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add head request for stream #136

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,22 @@ export const parameters = [
}
];

export const head: Operation = (req, res) => {

const channel = _.channel.get(req.params.type as ChannelType, req.params.channel);

if (channel === null) {
api.responseError(res, 404);
return;
}

const userId = (req.ip || "unix") + ":" + (req.socket.remotePort || Date.now());

res.setHeader("Content-Type", "video/MP2T");
res.setHeader("X-Mirakurun-Tuner-User-ID", userId);
res.status(200).end();
};

export const get: Operation = (req, res) => {

const channel = _.channel.get(req.params.type as ChannelType, req.params.channel);
Expand Down Expand Up @@ -101,6 +117,31 @@ export const get: Operation = (req, res) => {
.catch((err) => api.responseStreamErrorHandler(res, err));
};

head.apiDoc = {
tags: ["channels", "services", "stream"],
operationId: "getServiceStreamByChannel",
produces: ["video/MP2T"],
responses: {
200: {
description: "OK",
headers: {
"X-Mirakurun-Tuner-User-ID": {
type: "string"
}
}
},
404: {
description: "Not Found"
},
503: {
description: "Tuner Resource Unavailable"
},
default: {
description: "Unexpected Error"
}
}
};

get.apiDoc = {
tags: ["channels", "services", "stream"],
operationId: "getServiceStreamByChannel",
Expand Down
41 changes: 41 additions & 0 deletions src/Mirakurun/api/channels/{type}/{channel}/stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,22 @@ export const parameters = [
}
];

export const head: Operation = (req, res) => {

const channel = _.channel.get(req.params.type as ChannelType, req.params.channel);

if (channel === null) {
api.responseError(res, 404);
return;
}

const userId = (req.ip || "unix") + ":" + (req.socket.remotePort || Date.now());

res.setHeader("Content-Type", "video/MP2T");
res.setHeader("X-Mirakurun-Tuner-User-ID", userId);
res.status(200).end();
};

export const get: Operation = (req, res) => {

const channel = _.channel.get(req.params.type as ChannelType, req.params.channel);
Expand Down Expand Up @@ -85,6 +101,31 @@ export const get: Operation = (req, res) => {
.catch((err) => api.responseStreamErrorHandler(res, err));
};

head.apiDoc = {
tags: ["channels", "stream"],
operationId: "getChannelStream",
produces: ["video/MP2T"],
responses: {
200: {
description: "OK",
headers: {
"X-Mirakurun-Tuner-User-ID": {
type: "string"
}
}
},
404: {
description: "Not Found"
},
503: {
description: "Tuner Resource Unavailable"
},
default: {
description: "Unexpected Error"
}
}
};

get.apiDoc = {
tags: ["channels", "stream"],
operationId: "getChannelStream",
Expand Down
41 changes: 41 additions & 0 deletions src/Mirakurun/api/programs/{id}/stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,22 @@ export const parameters = [
}
];

export const head: Operation = (req, res) => {

const program = _.program.get(req.params.id as any as number);

if (program === null) {
api.responseError(res, 404);
return;
}

const userId = (req.ip || "unix") + ":" + (req.socket.remotePort || Date.now());

res.setHeader("Content-Type", "video/MP2T");
res.setHeader("X-Mirakurun-Tuner-User-ID", userId);
res.status(200).end();
};

export const get: Operation = (req, res) => {

const program = _.program.get(req.params.id as any as number);
Expand Down Expand Up @@ -81,6 +97,31 @@ export const get: Operation = (req, res) => {
.catch((err) => api.responseStreamErrorHandler(res, err));
};

head.apiDoc = {
tags: ["programs", "stream"],
operationId: "getProgramStream",
produces: ["video/MP2T"],
responses: {
200: {
description: "OK",
headers: {
"X-Mirakurun-Tuner-User-ID": {
type: "string"
}
}
},
404: {
description: "Not Found"
},
503: {
description: "Tuner Resource Unavailable"
},
default: {
description: "Unexpected Error"
}
}
};

get.apiDoc = {
tags: ["programs", "stream"],
operationId: "getProgramStream",
Expand Down
41 changes: 41 additions & 0 deletions src/Mirakurun/api/services/{id}/stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,22 @@ export const parameters = [
}
];

export const head: Operation = (req, res) => {

const service = _.service.get(req.params.id as any as number);

if (service === null || service === undefined) {
api.responseError(res, 404);
return;
}

const userId = (req.ip || "unix") + ":" + (req.socket.remotePort || Date.now());

res.setHeader("Content-Type", "video/MP2T");
res.setHeader("X-Mirakurun-Tuner-User-ID", userId);
res.status(200).end();
};

export const get: Operation = (req, res) => {

const service = _.service.get(req.params.id as any as number);
Expand Down Expand Up @@ -78,6 +94,31 @@ export const get: Operation = (req, res) => {
.catch((err) => api.responseStreamErrorHandler(res, err));
};

head.apiDoc = {
tags: ["services", "stream"],
operationId: "getServiceStream",
produces: ["video/MP2T"],
responses: {
200: {
description: "OK",
headers: {
"X-Mirakurun-Tuner-User-ID": {
type: "string"
}
}
},
404: {
description: "Not Found"
},
503: {
description: "Tuner Resource Unavailable"
},
default: {
description: "Unexpected Error"
}
}
};

get.apiDoc = {
tags: ["services", "stream"],
operationId: "getServiceStream",
Expand Down
Loading