-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
209 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { enhanceFeedbackVote } from '../../../../lib/mongo.js'; | ||
import template from './template.html'; | ||
import {renderHtml} from '../../../../lib/sso-render.js'; | ||
|
||
export const onRequestPost = async (context) => { | ||
const { env, request } = context; | ||
const data = await request.formData(); | ||
|
||
const q = data.get('q'); | ||
const token = data.get('token'); | ||
const contact = data.get('contact'); | ||
const comment = data.get('comment'); | ||
|
||
const success = await enhanceFeedbackVote(env, {token, comment, contact}); | ||
|
||
const view = { | ||
success, | ||
noSuccess: !success, | ||
q, | ||
}; | ||
|
||
const html = await renderHtml(template, view); | ||
return new Response(html, { | ||
headers: { | ||
'content-type': 'text/html', | ||
}, | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{{{ before }}} | ||
<main> | ||
{{#success}} | ||
<h1>Thanks!</h1> | ||
<p>Many thanks for your time. It means a lot to me!</p> | ||
<a href="/?q={{ q }}">Now, back to your business!</a> | ||
{{/success}} | ||
{{#noSuccess}} | ||
<h1>Ufff</h1> | ||
<p>Something went wrong with saving your feedback. Try CMD(ctrl) + R, maybe it will work out second time.</p> | ||
{{/noSuccess}} | ||
</main> | ||
|
||
{{{ after }}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { createHash, randomBytes } from 'node:crypto'; | ||
import { registerFeedbackVote } from '../../../lib/mongo.js'; | ||
import template from './template.html'; | ||
import {renderHtml} from '../../../lib/sso-render.js'; | ||
|
||
export const onRequestPost = async (context) => { | ||
const { env, request } = context; | ||
const data = await request.formData(); | ||
|
||
const pseudoRandom = randomBytes(8).toString('hex'); | ||
const token = createHash('sha256').update(pseudoRandom).digest('hex'); | ||
|
||
const vote = parseInt(data.get('vote'), 10); | ||
const q = data.get('q'); | ||
|
||
const insertedId = await registerFeedbackVote(env, {q, vote, token}); | ||
|
||
const view = { | ||
q, | ||
token, | ||
success: !!insertedId, | ||
}; | ||
|
||
const html = await renderHtml(template, view); | ||
return new Response(html, { | ||
headers: { | ||
'content-type': 'text/html', | ||
}, | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{{{ before }}} | ||
<main> | ||
<h1>Thank you</h1> | ||
<p>Many thanks for your feedback. If you want you can add some more!</p> | ||
<p>Once you send this form, it would be saved in kukei.eu database and removed once your feedback is processed. <br/> I might contact you later if you provide your contact info.</p> | ||
<form action="/api/feedback/enhance" method="POST" class="feedback-enhance-form"> | ||
<input type="hidden" name="token" value="{{ token }}" /> | ||
<input type="hidden" value="{{ q }}" name="q" /> | ||
<div class="feedback-enhance-form__group"> | ||
<label for="comment">Your comment</label> | ||
<textarea id="comment" name="comment"></textarea> | ||
</div> | ||
<div class="feedback-enhance-form__group"> | ||
<label for="contact">How to contact you?</label> | ||
<input type="text" id="contact" name="contact" placeholder="Mastodon handle, email, whatever you wish" /> | ||
</div> | ||
<button type="submit">Send</button> | ||
<a href="/?q={{ q }}">nah, send me back to my results</a> | ||
</form> | ||
</main> | ||
{{{ after }}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters