mirror of
https://github.com/donlon/cloudflare-error-page.git
synced 2025-12-19 14:59:28 +00:00
editor: support editing from other shared pages
This commit is contained in:
@@ -41,7 +41,8 @@
|
||||
}
|
||||
})
|
||||
|
||||
const initialConfig = {
|
||||
// can be changed if specified by '?from=<name>'
|
||||
let initialConfig = {
|
||||
"html_title": "cloudflare.com | 500: Internal server error",
|
||||
"title": "Internal server error",
|
||||
"error_code": 500,
|
||||
@@ -139,6 +140,30 @@
|
||||
},
|
||||
};
|
||||
|
||||
const urlParams = new URLSearchParams(window.location.search);
|
||||
const defaultPresetName = urlParams.get('from');
|
||||
if (defaultPresetName && defaultPresetName.indexOf('/') < 0) {
|
||||
fetch(`../s/${defaultPresetName}`, {
|
||||
headers: {
|
||||
'Accept': 'application/json'
|
||||
},
|
||||
})
|
||||
.then(response => {
|
||||
if (!response.ok) {
|
||||
throw new Error('failed to get preset');
|
||||
}
|
||||
return response.json();
|
||||
})
|
||||
.then(result => {
|
||||
if (result.status != 'ok') {
|
||||
return
|
||||
}
|
||||
console.log(result.parameters)
|
||||
initialConfig = result.parameters
|
||||
loadConfig(initialConfig);
|
||||
})
|
||||
}
|
||||
|
||||
/* Utilities */
|
||||
function $(id) { return document.getElementById(id); }
|
||||
|
||||
|
||||
@@ -57,8 +57,16 @@ def create():
|
||||
|
||||
@bp.get('/<name>')
|
||||
def get(name: str):
|
||||
accept = request.headers.get('Accept', '')
|
||||
is_json = 'application/json' in accept
|
||||
|
||||
item = db.session.query(models.Item).filter_by(name=name).first()
|
||||
if not item:
|
||||
if is_json:
|
||||
return jsonify({
|
||||
'status': 'not-found'
|
||||
})
|
||||
else:
|
||||
return abort(404)
|
||||
params = item.params
|
||||
params = {
|
||||
@@ -73,4 +81,11 @@ def get(name: str):
|
||||
'text': 'CF Error Page Editor',
|
||||
'link': f'https://virt.moe/cloudflare-error-page/editor/?from={name}',
|
||||
}
|
||||
|
||||
if is_json:
|
||||
return jsonify({
|
||||
'status': 'ok',
|
||||
'parameters': params,
|
||||
})
|
||||
else:
|
||||
return render_cf_error_page(params=params, allow_html=False, use_cdn=True), 200
|
||||
|
||||
Reference in New Issue
Block a user