mirror of
https://github.com/HeyPuter/puter
synced 2024-11-14 22:06:00 +00:00
feat: add querystring-informed errors
This commit is contained in:
parent
616f28d1d4
commit
e7c0b8320a
@ -16,6 +16,7 @@
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
const { URLSearchParams } = require("node:url");
|
||||
const { quot } = require("../util/strutil");
|
||||
|
||||
/**
|
||||
@ -519,6 +520,24 @@ module.exports = class APIError {
|
||||
};
|
||||
}
|
||||
|
||||
querystringize (extra) {
|
||||
return new URLSearchParams(this.querystringize_(extra));
|
||||
}
|
||||
|
||||
querystringize_ (extra) {
|
||||
const fields = {};
|
||||
for ( const k in this.fields ) {
|
||||
fields[`field_${k}`] = this.fields[k];
|
||||
}
|
||||
return {
|
||||
...extra,
|
||||
error: true,
|
||||
message: this.message,
|
||||
status: this.status,
|
||||
...fields,
|
||||
};
|
||||
}
|
||||
|
||||
get message () {
|
||||
const message = typeof this._message === 'function'
|
||||
? this._message(this.fields)
|
||||
|
@ -317,7 +317,7 @@ router.all('*', async function(req, res, next) {
|
||||
// index.js
|
||||
if(path === '/'){
|
||||
const svc_puterHomepage = Context.get('services').get('puter-homepage');
|
||||
return svc_puterHomepage.send(res, {
|
||||
return svc_puterHomepage.send({ req, res }, {
|
||||
title: app_title,
|
||||
description: description || config.short_description,
|
||||
short_description: config.short_description,
|
||||
|
@ -32,8 +32,28 @@ class PuterHomepageService extends BaseService {
|
||||
this.service_scripts.push(url);
|
||||
}
|
||||
|
||||
async send (res, meta, launch_options) {
|
||||
async send ({ req, res }, meta, launch_options) {
|
||||
const config = this.global_config;
|
||||
|
||||
if (
|
||||
req.query['puter.app_instance_id'] ||
|
||||
req.query['error_from_within_iframe']
|
||||
) {
|
||||
const easteregg = [
|
||||
'puter in puter?',
|
||||
'Infinite recursion!',
|
||||
'what\'chu cookin\'?',
|
||||
];
|
||||
const message = req.query.message ||
|
||||
easteregg[
|
||||
Math.floor(Math.random(easteregg.length))
|
||||
];
|
||||
|
||||
return res.send(this.generate_error_html({
|
||||
message,
|
||||
}));
|
||||
}
|
||||
|
||||
return res.send(this.generate_puter_page_html({
|
||||
env: config.env,
|
||||
|
||||
@ -271,6 +291,38 @@ class PuterHomepageService extends BaseService {
|
||||
|
||||
</html>`;
|
||||
};
|
||||
|
||||
generate_error_html ({ message }) {
|
||||
return `
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<style type="text/css">
|
||||
@font-face {
|
||||
font-family: 'Inter';
|
||||
src: url('/fonts/Inter-Thin.ttf') format('truetype');
|
||||
font-weight: 100;
|
||||
}
|
||||
BODY {
|
||||
box-sizing: border-box;
|
||||
margin: 0;
|
||||
height: 100vh;
|
||||
width: 100vw;
|
||||
background-color: #2f70ab;
|
||||
color: #f2f7f7;
|
||||
font-family: "Inter", "Helvetica Neue", HelveticaNeue, Helvetica, Arial, sans-serif;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>${message}</h1>
|
||||
</body>
|
||||
</html>
|
||||
`;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
|
@ -287,6 +287,16 @@ window.initgui = async function(options){
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------
|
||||
// Display an error if the query parameters have an error
|
||||
//--------------------------------------------------------------------------------------
|
||||
if ( window.url_query_params.has('error') ) {
|
||||
// TODO: i18n
|
||||
await UIAlert({
|
||||
message: window.url_query_params.get('message')
|
||||
});
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------
|
||||
// Get user referral code from URL query params
|
||||
// i.e. https://puter.com/?r=123456
|
||||
|
Loading…
Reference in New Issue
Block a user