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

File thumbnails broken in History Panel when file is placed inside folder(s) #2009

Closed
mdziekon opened this issue Sep 13, 2024 · 2 comments
Closed
Labels
⚡ Type: Bug Something isn't working

Comments

@mdziekon
Copy link
Contributor

mdziekon commented Sep 13, 2024

Mainsail Version:

2.12.0

Browser:

Firefox

Device:

Desktop PC

Operating System:

Linux

What happened?

When using History page / panel, files which are placed in folder(s) do not have proper thumbnail displayed, making it much harder to quickly find entries we are looking for. Files placed in the root directory do not exhibit this behavior.

thumbnail_bug

What did you expect to happen instead?

Files with thumbnails available should have that thumbnail displayed, regardless of their location in file system.

How to reproduce this bug?

  1. Create a folder
  2. Place a model (with a thumbnail) in that folder
  3. Print it (or at least attempt to print it so that it appears in History page)
  4. Go to History page

Additional information:

This appears to be a regression caused by the refactoring done in #1274. The culprit seems to be incorrect creation of thumbnail url for "small thumbnails", which incorrectly removes the final / character needed to build correct relative thumbnail path. This does not occur for "big thumbnails".

Previous, working code:
https://github.com/mainsail-crew/mainsail/pull/1274/files#diff-21c7ea907f2434c89b31411768fd6e832d8b9afd3597a8a5cdb835343ef03319L903-L944

New, broken code:
https://github.com/mainsail-crew/mainsail/pull/1274/files#diff-26b52f4bf48f9c0010205b6d9b658c3f1f329ceaea65dae5bfc28d7b62058426R150-R180

I'll post a patch for this bug shortly, as I've already fixed it in my local version.

@mdziekon mdziekon added the ⚡ Type: Bug Something isn't working label Sep 13, 2024
@meteyou
Copy link
Member

meteyou commented Sep 13, 2024

@mdziekon your links to the preview/new code doesn't work for me. can you pls a link to the file with line itself and not in the PR view?

@mdziekon
Copy link
Contributor Author

@meteyou right, that's probably because Github collapses both of these files by default, therefore hotlinking to specific lines does not work as intended.

Here's perma-link to working code:

getSmallThumbnail(item: ServerHistoryStateJob) {
if ('metadata' in item && 'thumbnails' in item.metadata && item.metadata.thumbnails.length) {
const thumbnail = item.metadata.thumbnails.find(
(thumb: any) =>
thumb.width >= thumbnailSmallMin &&
thumb.width <= thumbnailSmallMax &&
thumb.height >= thumbnailSmallMin &&
thumb.height <= thumbnailSmallMax
)
let relative_url = ''
if (item.filename.lastIndexOf('/') !== -1) {
relative_url = item.filename.substr(0, item.filename.lastIndexOf('/') + 1)
}
if (thumbnail && 'relative_path' in thumbnail) {
return `${this.apiUrl}/server/files/gcodes/${encodeURI(
relative_url + thumbnail.relative_path
)}?timestamp=${item.metadata.modified}`
}
}
return false
}
getBigThumbnail(item: ServerHistoryStateJob) {
if ('metadata' in item && 'thumbnails' in item.metadata && item.metadata.thumbnails.length) {
const thumbnail = item.metadata.thumbnails.find((thumb: any) => thumb.width >= thumbnailBigMin)
let relative_url = ''
if (item.filename.lastIndexOf('/') !== -1) {
relative_url = item.filename.substr(0, item.filename.lastIndexOf('/') + 1)
}
if (thumbnail && 'relative_path' in thumbnail)
return `${this.apiUrl}/server/files/gcodes/${encodeURI(
relative_url + thumbnail.relative_path
)}?timestamp=${item.metadata.modified}`
}
return false
}

Here's perma-link to broken code:

get smallThumbnail() {
const thumbnail = this.thumbnails.find(
(thumb: any) =>
thumb.width >= thumbnailSmallMin &&
thumb.width <= thumbnailSmallMax &&
thumb.height >= thumbnailSmallMin &&
thumb.height <= thumbnailSmallMax
)
if (!thumbnail) return false
let relative_url = ''
if (this.job.filename.lastIndexOf('/') !== -1) {
relative_url = this.job.filename.substring(0, this.job.filename.lastIndexOf('/') + 1)
}
return `${this.apiUrl}/server/files/gcodes/${encodeURI(relative_url + thumbnail.relative_path)}?timestamp=${this
.job.metadata?.modified}`
}
get bigThumbnail() {
const thumbnail = this.thumbnails.find((thumb: any) => thumb.width >= thumbnailBigMin)
if (!thumbnail) return false
let relative_url = ''
if (this.job.filename.lastIndexOf('/') !== -1) {
relative_url = this.job.filename.substring(0, this.job.filename.lastIndexOf('/') + 1)
}
return `${this.apiUrl}/server/files/gcodes/${encodeURI(relative_url + thumbnail.relative_path)}?timestamp=${this
.job.metadata?.modified}`
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
⚡ Type: Bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants