synapse-react-client
Version:
[](https://badge.fury.io/js/synapse-react-client) [](https://github.com/prettier/prettie
67 lines (66 loc) • 2.05 kB
JavaScript
import { useCreateEntity as u, useUpdateEntity as m } from "../../../synapse-queries/entity/useEntity.js";
import { useCreateExternalFileHandle as p } from "../../../synapse-queries/file/useFileHandle.js";
import { useMutation as E } from "@tanstack/react-query";
import { useSynapseContext as F } from "../../context/SynapseContext.js";
import { isContainerType as g, convertToEntityType as T } from "../../functions/EntityTypeUtils.js";
function x(e) {
let n = "";
if (e != null) {
const t = e.lastIndexOf("/");
if (t > -1) {
const r = e.indexOf("?", t);
r > -1 ? n = e.substring(t + 1, r) : n = e.substring(t + 1);
}
}
return n;
}
function k(e) {
const { synapseClient: n } = F(), { mutateAsync: t } = p(), { mutateAsync: r } = u(), { mutateAsync: f } = m();
return E({
...e,
mutationFn: async (c) => {
const { url: y, entityId: a } = c;
let i = c.name;
(i == "" || i == null) && (i = x(y));
const o = await n.entityServicesClient.getRepoV1EntityId(
{ id: a }
);
let l;
if (o.concreteType === "org.sagebionetworks.repo.model.FileEntity")
l = !0;
else if (g(T(o.concreteType)))
l = !1;
else
throw new Error(
`The ${a} is not a FileEntity or a container, got concreteType ${o.concreteType}`
);
const d = await t({
externalFileHandleInterface: {
concreteType: "org.sagebionetworks.repo.model.file.ExternalFileHandle",
fileName: i,
externalURL: y
}
});
if (l) {
const s = {
...o,
dataFileHandleId: d.id
};
return await f(s);
} else {
const s = {
name: i,
concreteType: "org.sagebionetworks.repo.model.FileEntity",
parentId: a,
dataFileHandleId: d.id
};
return await r(s);
}
}
});
}
export {
x as getFileNameFromExternalUrl,
k as useLinkFileEntityToURL
};
//# sourceMappingURL=useLinkFileEntityToURL.js.map