Skip to content
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

Image Uploads #287

Open
wants to merge 26 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
714c73e
Add library multiparty to parse form data.
Nov 18, 2023
b166eb8
Use BoardDataList instead of plain object
Nov 18, 2023
8fa13cb
Return public interface for Sockets object
Nov 18, 2023
073ff19
Image asset uploads and updates.
Nov 18, 2023
b23bf11
Validate image size before allowing upload.
Nov 18, 2023
7abbda4
Get MIME type before returning image assets.
Nov 18, 2023
ff2768f
Remove old TODO
Nov 18, 2023
f278e68
Use XHR to upload images. Allows access to progress.
Nov 18, 2023
6b847cf
Move all image upload stuff to image tool
Nov 18, 2023
bf67be1
Use image tool to initiate upload
Nov 18, 2023
15781ee
Delete images if they are no longer in use.
Nov 18, 2023
f1cd94d
Drop onto board, not canvas.
Nov 18, 2023
daed5e3
Remove unnecessary console.log
Nov 18, 2023
962bb22
Use cell cursor for image tool.
Nov 18, 2023
9bf0e3f
Disable image upload if Image tool is in block list
Nov 18, 2023
5d82a78
Remove tmp file after image upload.
Nov 18, 2023
d09411b
Don't block main handler fn when serving board image assets.
Nov 18, 2023
84ff1e1
Validate image uploads on client and server.
Nov 18, 2023
1a815a6
Add log for when unused images are purged
Nov 18, 2023
c321964
Ensure that board image asset URLs always point to current domain.
Nov 19, 2023
1e3708e
Use fs.promises to read board image assets.
Nov 19, 2023
7fe1fe3
Use board name and asset ID to build image href
Nov 20, 2023
b0e47a1
Fix image purge.
Nov 20, 2023
231d3fd
Attach click and drag/drop handlers to canvas, not drawingArea
Nov 20, 2023
dfd96b1
Add tests for image upload tool.
Nov 20, 2023
05d0ea2
Merge branch 'master' into master
atomdmac Nov 27, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion client-data/tools/image/image.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,15 @@
}
}

/**
* Gets the absolute URL of a relative URL. Ensures that the URL points to
* the same origin as the current page.
*/
function getAbsoluteImageUrl(relativeUrl) {
const normalizedUrl = relativeUrl.startsWith('/') ? relativeUrl : `/${relativeUrl}`;
return `${window.location.origin}${normalizedUrl}`;
}

var svg = Tools.svg;
/**
* Creates a new image element on the canvas, or updates an existing image
Expand All @@ -80,7 +89,7 @@
function createImageElement(data) {
var img = svg.getElementById(data.id) || Tools.createSVGElement("image");
img.setAttribute("id", data.id);
img.setAttribute("href", data.src);
img.setAttribute("href", getAbsoluteImageUrl(data.src));
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is complicated. Can we remove the src altogether ?

Suggested change
img.setAttribute("href", getAbsoluteImageUrl(data.src));
img.setAttribute("href", "./images/" + data.id);

that would stress me less :)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How would the browser know where to pull the image to display from?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The browser would make a request to boards/{boardname}/images/{image_id}, the server would check that the image exists, and if so, serve it.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yours is a much better approach 😅 This has been updated.

img.setAttribute("x", data.x);
img.setAttribute("y", data.y);

Expand Down