somethinggeneric / bookmark-sync Goto Github PK
View Code? Open in Web Editor NEWServer for syncing bookmarks
License: MIT License
Server for syncing bookmarks
License: MIT License
Items that need work:
script.js
in the extension subfolder so that the login/register buttons are appropriately hidden/shown as needed.script.js
to make it a more manageable codebase going forwards.script.js
to pull from endpoint /bookmarks
on the upstream API, and then use the returned json to add/remove bookmarks as needed.server/app.py
to support the above functionalityChecklist:
Refactor script.js for better visibility control of login/register buttons
- In extension/script.js, create a function that checks the session status and updates the visibility of the login/register buttons accordingly.
Refactor script.js for a more manageable codebase
- In extension/script.js, modularize the code by separating different functionalities into different functions.
- In extension/script.js, organize the code in a more structured way.
Create a new function in script.js to interact with /bookmarks endpoint
- In extension/script.js, create a new function that sends a GET request to the
/bookmarks
endpoint.- In extension/script.js, handle the returned JSON data in the new function to add/remove bookmarks as needed.
Implement /bookmarks endpoint in server/app.py
- In server/app.py, create a new route handler for the
/bookmarks
endpoint.- In server/app.py, return the required JSON data in the new route handler.
Checklist:
Refactor script.js for better visibility control of login/register buttons
- In extension/script.js, create a function that checks the session status and updates the visibility of the login/register buttons accordingly.
Refactor script.js for a more manageable codebase
- In extension/script.js, modularize the code by separating different functionalities into different functions.
- In extension/script.js, organize the code in a more structured way.
Create a new function in script.js to interact with /bookmarks endpoint
- In extension/script.js, create a new function that sends a GET request to the
/bookmarks
endpoint.- In extension/script.js, handle the returned JSON data in the new function to add/remove bookmarks as needed.
Implement /bookmarks endpoint in server/app.py
- In server/app.py, create a new route handler for the
/bookmarks
endpoint.- In server/app.py, return the required JSON data in the new route handler.
/bookmarks
endpoint.Parent issue: #4
extension/script.js
• Add a new function named
fetchBookmarks
. This function should send a GET request to the/bookmarks
endpoint. Use thefetch
function to send the request. The endpoint URL should be constructed using theendpoint
variable and the string '/bookmarks'.
• In thefetchBookmarks
function, handle the returned response. Parse the response as JSON using thejson
method of the response object.
• After parsing the response, iterate over the returned data. For each item in the data, check if a bookmark with the same URL already exists. If it does not exist, add a new bookmark with the URL and title from the item. If it does exist and the title is different, update the title of the bookmark. If the item has a property indicating that the bookmark should be removed, remove the bookmark.
• Call thefetchBookmarks
function after the user has successfully logged in. This can be done in thethen
block of thefetch
call in theauth
function, after the response has been logged.
As noted in the comments starting on line 16 and 21 of app.py, respectively.
Both should use the simpleusers functions mentioned. Here's a cut of their documentation to help you.
def auth_user(self, uid, attempt)
Authenticates a user.
Args
uid : str
User ID or filename.
attempt : str
Password attempt for authentication.
Returns
bool
True if authentication is successful, False otherwise.
def make_user(self, uid, passw)
Creates a new user.
Args
uid : str
User ID or filename.
passw : str
User password.
Returns
None
server/app.py
• Implement the first TODO on line 16 by calling the
make_user
function from thesimpleusers
module with theusername
andpassword
parameters obtained from the request.
• Implement the second TODO on line 21 by calling theauth_user
function from thesimpleusers
module with theusername
andpassword
parameters obtained from the request. Return the session token if authentication is successful.
Parent issue: #4
extension/script.js
• Separate the code for fetching bookmarks from the server into a separate function named fetchBookmarksFromServer.
• Separate the code for adding a bookmark into a separate function named addBookmark.
• Separate the code for checking if a bookmark exists into a separate function named bookmarkExists.
• Separate the code for removing a bookmark into a separate function named removeBookmark.
• Separate the code for getting local bookmarks into a separate function named getLocalBookmarks.
• Group the functions related to bookmarks (fetchBookmarksFromServer, addBookmark, bookmarkExists, removeBookmark, getLocalBookmarks) together in the code.
• Separate the code for showing an element into a separate function named showElement.
• Separate the code for hiding an element into a separate function named hideElement.
• Separate the code for updating button visibility into a separate function named updateButtonVisibility.
• Group the functions related to UI (showElement, hideElement, updateButtonVisibility) together in the code.
• Separate the code for checking session status into a separate function named checkSessionStatus.
• Group the function related to session (checkSessionStatus) with the functions related to UI.
• Separate the code for authentication into a separate function named auth.
• Group the function related to authentication (auth) with the functions related to session and UI.
• Test the code after refactoring to ensure it still works as expected.
Parent issue: #4
extension/script.js
• Modify the
checkSessionStatus()
function to callupdateButtonVisibility(sessionExists)
after checking the session status. This will ensure that the button visibility is updated every time the session status is checked.
• Modify the event listener for the "endpointsetbutton" to call thecheckSessionStatus()
function instead of directly checking the session status and updating the button visibility.
• Modify the event listener for the "endpointremovebutton" to call thecheckSessionStatus()
function instead of directly checking the session status and updating the button visibility.
• Modify the event listener for the "signinbutton" to call thecheckSessionStatus()
function instead of directly checking the session status and updating the button visibility.
• Modify the event listener for the "registerbutton" to call thecheckSessionStatus()
function instead of directly checking the session status and updating the button visibility.
Parent issue: #4
extension/script.js
• Create a new function named
checkSessionStatus
. This function should usebrowser.storage.local.get
to retrieve the session token from the local storage. If a session token exists, the function should returntrue
; otherwise, it should returnfalse
.
• Create a new function namedupdateButtonVisibility
. This function should take a boolean parameter namedsessionExists
. IfsessionExists
istrue
, the function should hide the login and register buttons by callinghideE
with "signinbutton" and "registerbutton" as arguments, respectively. IfsessionExists
isfalse
, the function should show the login and register buttons by callingshowE
with "signinbutton" and "registerbutton" as arguments, respectively.
• In the event listener for the DOMContentLoaded event, replace the existing code that checks the session status and updates the button visibility with calls tocheckSessionStatus
andupdateButtonVisibility
.
• In the event listeners for the "endpointsetbutton" and "endpointremovebutton" clicks, after the endpoint is set or removed, callcheckSessionStatus
andupdateButtonVisibility
to update the button visibility based on the new session status.
/bookmarks
endpoint.Parent issue: #4
server/app.py
• Replace the current implementation of the
/bookmarks
endpoint with a new function that fetches the bookmark data from the database.
• The new function should return the bookmark data in the required JSON format.
• Add a check to ensure that the/bookmarks
endpoint is only accessible to authenticated users.
Parent issue: #4
extension/script.js
• Create a new function named 'setEndpoint' that encapsulates the logic for setting the endpoint. This function should take the endpoint as a parameter and set it in the browser's local storage.
• Create a new function named 'getEndpoint' that encapsulates the logic for getting the endpoint from the browser's local storage.
• Create a new function named 'auth' that encapsulates the logic for authentication. This function should take the mode (signin or register) as a parameter and perform the appropriate action.
• Create a new function named 'updateButtonVisibility' that encapsulates the logic for updating the visibility of the buttons. This function should take a boolean parameter indicating whether a session exists or not.
• Create a new function named 'checkSessionStatus' that encapsulates the logic for checking the session status. This function should return a promise that resolves with a boolean indicating whether a session exists or not.
• Organize these functions in a more structured way by grouping related functions together and separating unrelated functions.
• Refactor the code to make it more readable and maintainable by following best practices for writing JavaScript code.
/bookmarks
endpoint.Parent issue: #4
server/app.py
• Replace the current
/bookmarks
route handler with a new one. The new route handler should fetch the bookmarks from the database and return them as JSON data.
• Add the@login_required
decorator to the/bookmarks
route handler to ensure that it is accessible only to authenticated users.
/bookmarks
endpoint.Parent issue: #4
server/app.py
• Add a new route handler for the
/bookmarks
endpoint using the@app.route
decorator. The route should respond to GET requests.
• In the new route handler, return a list of bookmarks. Each bookmark should be a dictionary with keys for the bookmark's title and URL. For now, you can return a static list of bookmarks for testing purposes.
/bookmarks
endpoint.Parent issue: #4
server/app.py
• Add a new route handler for the
/bookmarks
endpoint using the@app.route
decorator. The route should accept both GET and POST requests.
• In the new route handler, check if the request method is GET. If it is, return a JSON object with a list of all bookmarks. For now, you can return a static list of bookmarks.
• If the request method is POST, extract the bookmark data from the request body and add it to the list of bookmarks. Then return a success message in JSON format.
Parent issue: #4
extension/script.js
• Create a function named
checkSessionStatus
that checks if a session exists. This function should return a boolean value indicating whether a session exists or not. Use the existing code in thecheckSessionStatus
function as a starting point, but modify it to return a boolean value instead of resolving a promise.
• Create a function namedupdateButtonVisibility
that takes a boolean argumentsessionExists
. This function should callhideElement
for the "signinbutton" and "registerbutton" ifsessionExists
is true, andshowElement
for these buttons ifsessionExists
is false.
• Replace the existing calls tohideElement
andshowElement
for the "signinbutton" and "registerbutton" with calls toupdateButtonVisibility
. Pass the result ofcheckSessionStatus
as an argument toupdateButtonVisibility
.
• In theDOMContentLoaded
event listener, replace the existing call toupdateButtonVisibility
with a call tocheckSessionStatus
, and use the result to callupdateButtonVisibility
.
/bookmarks
endpoint.Parent issue: #4
extension/script.js
• Add a new function named
fetchBookmarks
that sends a GET request to the/bookmarks
endpoint. Use thefetch
function to send the request, and theendpoint
variable for the URL.
• In thefetchBookmarks
function, handle the returned response by converting it to JSON with thejson
method.
• After converting the response to JSON, iterate over the returned bookmarks. For each bookmark, check if it exists in the local bookmarks. If it does not exist, add it. If it exists in the local bookmarks but not in the server data, remove it.
/bookmarks
endpoint.Parent issue: #4
extension/script.js
• Create a new function named
syncBookmarks()
.
• InsidesyncBookmarks()
, send a GET request to the/bookmarks
endpoint using thefetch
function.
• Handle the returned response by converting it to JSON using thejson()
method.
• Iterate over the returned bookmarks. For each bookmark, check if it exists in the local bookmarks using thebookmarkExists(bookmark)
function. If it does not exist, add it using theaddBookmark(bookmark)
function.
• After adding the new bookmarks, iterate over the local bookmarks using thegetLocalBookmarks()
function. For each local bookmark, check if it exists in the returned bookmarks. If it does not exist, remove it using theremoveBookmark(bookmark)
function.
Parent issue: #4
extension/script.js
• Create a new function named 'setEndpoint' and move the code for setting the endpoint from the 'DOMContentLoaded' event listener to this new function.
• Create a new function named 'removeEndpoint' and move the code for removing the endpoint from the 'DOMContentLoaded' event listener to this new function.
• Create a new function named 'signIn' and move the code for signing in from the 'DOMContentLoaded' event listener to this new function.
• Create a new function named 'register' and move the code for registering from the 'DOMContentLoaded' event listener to this new function.
• Create a new function named 'showElement' and move the code for showing an element from the 'showE' function to this new function.
• Create a new function named 'hideElement' and move the code for hiding an element from the 'hideE' function to this new function.
• Group the newly created functions together and add comments to explain what each function does.
• Replace the calls to the old functions in the 'DOMContentLoaded' event listener with calls to the new functions.
fetchBookmarks
that sends a GET request to the /bookmarks
endpoint.fetchBookmarks
function, handle the returned JSON data to add/remove bookmarks as needed.Parent issue: #4
extension/script.js
• Add a new function
fetchBookmarks
that sends a GET request to the/bookmarks
endpoint. Use thefetch
API for this. Thefetch
function should be called with theendpoint
variable concatenated with the string '/bookmarks'.
• In thefetchBookmarks
function, handle the returned response by converting it to JSON using thejson
method of the response.
• After converting the response to JSON, iterate over the returned bookmarks. For each bookmark, check if it exists in the local bookmarks. If it does not exist, add it to the local bookmarks. This can be done using thebookmarkExists
andaddBookmark
functions.
• After iterating over the returned bookmarks, iterate over the local bookmarks. For each local bookmark, check if it exists in the returned bookmarks. If it does not exist, remove it from the local bookmarks. This can be done using theremoveBookmark
function.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.