@gemini-dock/protocol
Version:
Protocol utilities for Gemini Dock
56 lines (55 loc) • 2.06 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.respond = exports.CODES = void 0;
exports.CODES = {
REQUEST_INPUT: 10,
REQUEST_PASSWORD: 11,
SUCCESS: 20,
REDIRECT_TEMPORARY: 30,
REDIRECT_PERMANENT: 31,
FAIL_TEMPORARY: 40,
FAIL_SERVER_UNAVAILABLE: 41,
FAIL_CGI_ERROR: 42,
FAIL_PROXY_ERROR: 43,
FAIL_SLOW_DOWN: 44,
FAIL_PERMANENT: 50,
FAIL_NOT_FOUND: 51,
FAIL_GONE: 52,
FAIL_PROXY_REQUEST_ERROR: 53,
FAIL_BAD_REQUEST: 59,
CERTIFICATE_REQUIRED: 60,
CERTIFICATE_NOT_AUTHORIZED: 61,
CERTIFICATE_INVALID: 62
};
const respond = (code, body, type = 'text/gemini') => {
switch (code) {
case exports.CODES.CERTIFICATE_REQUIRED:
return { code, type: 'Certificate required for this route' };
case exports.CODES.CERTIFICATE_NOT_AUTHORIZED:
return { code, type: 'Certificate not authorized for this route' };
case exports.CODES.CERTIFICATE_INVALID:
return { code, type: 'Certificate invalid for this route' };
case exports.CODES.FAIL_BAD_REQUEST:
case exports.CODES.FAIL_CGI_ERROR:
case exports.CODES.FAIL_GONE:
case exports.CODES.FAIL_NOT_FOUND:
case exports.CODES.FAIL_PERMANENT:
case exports.CODES.FAIL_PROXY_ERROR:
case exports.CODES.FAIL_PROXY_REQUEST_ERROR:
case exports.CODES.FAIL_SERVER_UNAVAILABLE:
case exports.CODES.FAIL_SLOW_DOWN:
case exports.CODES.FAIL_TEMPORARY:
case exports.CODES.REDIRECT_PERMANENT:
case exports.CODES.REDIRECT_TEMPORARY:
return { code, type: body };
case exports.CODES.REQUEST_INPUT:
return { code, type: body || 'Please provide input' };
case exports.CODES.REQUEST_PASSWORD:
return { code, type: body || 'Please provide password' };
case exports.CODES.SUCCESS:
return { code, type, body };
default:
return { code, type: 'An error occurred' };
}
};
exports.respond = respond;