-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Feat/custom note url #1699
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
Feat/custom note url #1699
Conversation
8d6605f
to
9ded54e
Compare
106e457
to
d44be73
Compare
lib/note/service.js
Outdated
const { Note, ArchivedNoteAlias, sequelize } = require('../models') | ||
const realtime = require('../realtime/realtime') | ||
|
||
const forbiddenAlias = ['', 'new', 'me', 'history', '403', '404', '500', 'config'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jackycute Also public/docs/*.md
paths?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also config.forbiddenNoteIDs
lib/models/note.js
Outdated
@@ -223,6 +228,18 @@ module.exports = function (sequelize, DataTypes) { | |||
|
|||
Note.parseNoteId = function (noteId, callback) { | |||
async.series({ | |||
parseNoteIdByArchivedAlias: function (_callback) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not totally sure about why we keep the previously used alias in track?
What if the archived alias you about to change has been used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not totally sure about why we keep the previously used alias in track?
My thought is to avoid some user saved the archived alias but can't connect the note.
What if the archived alias you about to change has been used?
The user just change one that not be used. Or we need to set the special and personal prefix for the alias?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To make this PR be more specific, it's better not to add this feature for redirecting previous alias to new one.
I suggest to remove this and by adding a notice alert area in the custom note url modal like: Notice: the previous custom note url will not be redirected to the new one, please take your own risk to change this.
would help.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @Nick0603,
Thanks for your contribution, there are some suggestions:
- In general, we use strict mode in backend.
- Do not mix different asynchronous paradigm in a procedure.
- Maybe we can fill-in alias url in modal if the note already setup an alias url.
- To avoid some vulnerability, we only support these character in customize url: lowercase
letters, decimal digits, hyphen, underscore. And need check user input is valid both frontend and backend. Do not auto correct or filter out the input. - Alias would be conflict with another nodeId, shortid
lib/note/service.js
Outdated
return alias.replace(/( |\/)/, '') | ||
} | ||
|
||
const asyncGetNote = async (originAliasOrNoteId) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We already have getNoteById
function in note/index.js
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because the getNoteById
in note/index.js noget pure note row data.
I think controller
or service
should be choose the enough data to use.
But I also agree DRY is nice here, I will adjust it.
lib/note/index.js
Outdated
@@ -8,6 +8,7 @@ const { newCheckViewPermission, errorForbidden, responseCodiMD, errorNotFound, e | |||
const { updateHistory, historyDelete } = require('../history') | |||
const { actionPublish, actionSlide, actionInfo, actionDownload, actionPDF, actionGist, actionRevision, actionPandoc } = require('./noteActions') | |||
const realtime = require('../realtime/realtime') | |||
const serv = require('./service') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rename service -> noteAlias, and consider using object destruction
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would like to make the service is for all note controller, so I think the naming noteAlias is not suitable.
And the service will contains the common logic in controller and easy for testing.
77c3b03
to
1ee19ed
Compare
|
Signed-off-by: nick.chen <[email protected]>
Signed-off-by: nick.chen <[email protected]>
Co-authored-by: Yukai Huang <[email protected]> Signed-off-by: nick.chen <[email protected]>
Co-authored-by: Yukai Huang <[email protected]> Signed-off-by: nick.chen <[email protected]>
Signed-off-by: nick.chen <[email protected]>
1ee19ed
to
014790a
Compare
For example: The code mix two asynchronous paradigm, async/await and Promise. const conflictNote = await exports.getNote(alias)
.catch((err) => { throw err }) If you want to handle error in async/await, using try...catch statement. try {
const conflictNote = await exports.getNote(alias)
} catch ((err) => {
throw err
}) But, the catch statement just rethrow the error, we can remove it. const conflictNote = await exports.getNote(alias) |
Signed-off-by: nick.chen <[email protected]>
|
||
if (!note) { | ||
logger.error('update note alias failed: note not found.') | ||
return res.status(500).json({ status: 'error', message: 'Internal Error' }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return 404 for note not found
@@ -1266,6 +1277,62 @@ $('#revisionModalRevert').click(function () { | |||
editor.setValue(revision.content) | |||
ui.modal.revision.modal('hide') | |||
}) | |||
|
|||
// custom note url modal | |||
const updateNoteUrl = (noteUrl = '') => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rename: const updateNoteAliasUrl = (noteAliasUrl = '')
or const updateNoteCustomUrl = (noteCustomUrl = '')
return | ||
} | ||
|
||
updateNoteUrl(customUrl) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
handle error in catch statement:
updateNoteUrl(customUrl)
.then(({status}) => { .... })
.catch((err) => {
if (err.status === 400) .....
...
showErrorMessage('Something wrong.')
})
Big thanks @Nick0603 |
Relatied issue: #1478
story:
A created note

Click "Custom Note Url" in Menu

Type url you like and submit.

The url is customized and sync to all collaborators in real time.

Details:
If some users browse the past url, they will redirect to latest one automatically.
It will be blocked when the custom url is conflict with exist url.

But if the conflicted url is set by you in the past. You have right to set back.