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

Followups for OME-TIFF export #6874

Merged
merged 7 commits into from
Feb 27, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
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
2 changes: 1 addition & 1 deletion app/controllers/JobsController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ class JobsController @Inject()(jobDAO: JobDAO,
dataSet <- dataSetDAO.findOneByNameAndOrganizationName(dataSetName, organizationName) ?~> Messages(
"dataSet.notFound",
dataSetName) ~> NOT_FOUND
_ <- jobService.assertTiffExportBoundingBoxLimits(bbox)
_ <- jobService.assertTiffExportBoundingBoxLimits(bbox, mag)
userAuthToken <- wkSilhouetteEnvironment.combinedAuthenticatorService.findOrCreateToken(
request.identity.loginInfo)
command = "export_tiff"
Expand Down
12 changes: 7 additions & 5 deletions app/models/job/Job.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package models.job

import com.scalableminds.util.accesscontext.{DBAccessContext, GlobalAccessContext}
import com.scalableminds.util.geometry.BoundingBox
import com.scalableminds.util.geometry.{BoundingBox, Vec3Int}
import com.scalableminds.util.mvc.Formatter
import com.scalableminds.util.time.Instant
import com.scalableminds.util.tools.{Fox, FoxImplicits}
Expand Down Expand Up @@ -365,11 +365,13 @@ class JobService @Inject()(wkConf: WkConf,
_ <- workerDAO.findOneByDataStore(dataStoreName)
} yield ()

def assertTiffExportBoundingBoxLimits(bbox: String): Fox[Unit] =
def assertTiffExportBoundingBoxLimits(boundingBox: String, mag: Option[String]): Fox[Unit] =
for {
boundingBox <- BoundingBox.fromLiteral(bbox).toFox ?~> "job.export.tiff.invalidBoundingBox"
_ <- bool2Fox(boundingBox.volume <= wkConf.Features.exportTiffMaxVolumeMVx * 1024 * 1024) ?~> "job.export.tiff.volumeExceeded"
_ <- bool2Fox(boundingBox.dimensions.maxDim <= wkConf.Features.exportTiffMaxEdgeLengthVx) ?~> "job.export.tiff.edgeLengthExceeded"
parsedBoundingBox <- BoundingBox.fromLiteral(boundingBox).toFox ?~> "job.export.tiff.invalidBoundingBox"
parsedMag <- Vec3Int.fromMagLiteral(mag.getOrElse("1-1-1"), true) ?~> "job.export.tiff.invalidMag"
scaledBoundingBox = parsedBoundingBox / parsedMag
normanrz marked this conversation as resolved.
Show resolved Hide resolved
_ <- bool2Fox(scaledBoundingBox.volume <= wkConf.Features.exportTiffMaxVolumeMVx * 1024 * 1024) ?~> "job.export.tiff.volumeExceeded"
_ <- bool2Fox(scaledBoundingBox.dimensions.maxDim <= wkConf.Features.exportTiffMaxEdgeLengthVx) ?~> "job.export.tiff.edgeLengthExceeded"
} yield ()

}
1 change: 1 addition & 0 deletions conf/messages
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ job.disabled = Long-running jobs are not enabled for this WEBKNOSSOS instance.
job.worker.notFound = Could not find this worker in the database.
job.export.fileNotFound = Exported file not found. The link may be expired.
job.export.tiff.invalidBoundingBox = The selected bounding box could not be parsed, must be x,y,z,width,height,depth
job.export.tiff.invalidMag = The selected mag could not be parsed, must be x-y-z
job.export.tiff.volumeExceeded = The volume of the selected bounding box is too large.
job.export.tiff.edgeLengthExceeded = An edge length of the selected bounding box is too large.
job.inferNuclei.notAllowed.organization = Currently nuclei inferral is only allowed for datasets of your own organization.
Expand Down
29 changes: 10 additions & 19 deletions frontend/javascripts/admin/admin_rest_api.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { saveAs } from "file-saver";
import ResumableJS from "resumablejs";
import _ from "lodash";
import dayjs from "dayjs";
Expand Down Expand Up @@ -985,6 +984,15 @@ export function convertToHybridTracing(
});
}

export async function downloadWithFilename(downloadUrl: string) {
const link = document.createElement("a");
link.href = downloadUrl;
link.rel = "noopener";
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
}

export async function downloadAnnotation(
annotationId: string,
annotationType: APIAnnotationType,
Expand All @@ -1005,24 +1013,7 @@ export async function downloadAnnotation(
const maybeAmpersand = possibleVersionString === "" && !includeVolumeData ? "" : "&";

const downloadUrl = `/api/annotations/${annotationType}/${annotationId}/download?${possibleVersionString}${maybeAmpersand}${skipVolumeDataString}`;
const { buffer, headers } = await Request.receiveArraybuffer(downloadUrl, {
extractHeaders: true,
});

// Using headers to determine the name and type of the file.
const contentDispositionHeader = headers["content-disposition"];
const filenameStartingPart = 'filename="';
const filenameStartingPosition =
contentDispositionHeader.indexOf(filenameStartingPart) + filenameStartingPart.length;
const filenameEndPosition = contentDispositionHeader.indexOf('"', filenameStartingPosition + 1);
const filename = contentDispositionHeader.substring(
filenameStartingPosition,
filenameEndPosition,
);
const blob = new Blob([buffer], {
type: headers["content-type"],
});
saveAs(blob, filename);
normanrz marked this conversation as resolved.
Show resolved Hide resolved
await downloadWithFilename(downloadUrl);
}

// When the annotation is open, please use the corresponding method
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import features from "features";
import {
doWithToken,
downloadAnnotation,
downloadWithFilename,
getAuthToken,
startExportTiffJob,
} from "admin/admin_rest_api";
Expand Down Expand Up @@ -41,7 +42,6 @@ import {
import { formatBytes, formatScale } from "libs/format_utils";
import { BoundingBoxType, Vector3 } from "oxalis/constants";
import { useStartAndPollJob } from "admin/job/job_hooks";
import { saveAs } from "file-saver";
const CheckboxGroup = Checkbox.Group;
const { TabPane } = Tabs;
const { Paragraph, Text } = Typography;
Expand Down Expand Up @@ -290,7 +290,7 @@ function _DownloadModalView({
async onSuccess(job) {
if (job.resultLink != null) {
const token = await doWithToken(async (t) => t);
saveAs(`${job.resultLink}?token=${token}`);
downloadWithFilename(`${job.resultLink}?token=${token}`);
}
},
onFailure() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ case class BoundingBox(topLeft: Vec3Int, width: Int, height: Int, depth: Int) {
def *(that: Vec3Int): BoundingBox =
BoundingBox(topLeft * that, width * that.x, height * that.y, depth * that.z)

def /(that: Vec3Int): BoundingBox = BoundingBox(topLeft / that, width / that.x, height / that.y, depth / that.z)
normanrz marked this conversation as resolved.
Show resolved Hide resolved

def toSql: List[Int] =
List(topLeft.x, topLeft.y, topLeft.z, width, height, depth)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ case class Vec3Int(x: Int, y: Int, z: Int) {
def *(that: Int): Vec3Int =
Vec3Int(x * that, y * that, z * that)

def /(that: Vec3Int): Vec3Int =
Vec3Int(x / that.x, y / that.y, z / that.z)

def scale(s: Float): Vec3Int =
Vec3Int((x * s).toInt, (y * s).toInt, (z * s).toInt)

Expand Down