diff options
-rw-r--r-- | src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx | 95 | ||||
-rw-r--r-- | src/client/views/pdf/PDFViewer.tsx | 14 | ||||
-rw-r--r-- | src/server/DashUploadUtils.ts | 10 |
3 files changed, 58 insertions, 61 deletions
diff --git a/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx b/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx index a447a6ae4..76b9fd8db 100644 --- a/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx +++ b/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx @@ -1,4 +1,4 @@ -import { Button, Colors, Type } from '@dash/components'; +import { Button, Colors, NumberDropdown, Size, Type } from '@dash/components'; import { Slider } from '@mui/material'; import { Bezier } from 'bezier-js'; import { Property } from 'csstype'; @@ -2202,58 +2202,63 @@ export class CollectionFreeFormView extends CollectionSubView<Partial<collection ); } + @observable private _regenerateLoading = false; @observable private _regenInput = ''; + @observable private _canInteract = true; @observable private _drawingFillInput = ''; @observable private _regenLoading = false; @observable private _drawingFillLoading = false; - @observable private _fireflyRefStrength = 50; + @observable private _fireflyRefStrength = 0; componentAIView = () => { return ( - <div className="collectionfreeformview-aiView" onPointerDown={e => e.stopPropagation()}> - <div className="collectionfreeformview-aiView-options-container"> - <span className="collectionfreeformview-aiView-subtitle">Firefly:</span> - <div className="collectionfreeformview-aiView-options"> - <input - className="collectionfreeformview-aiView-prompt" - placeholder={this._drawingFillInput || StrCast(this.Document.title) || 'Describe image'} - type="text" - value={this._drawingFillInput} - onChange={action(e => (this._drawingFillInput = e.target.value))} + <div className="imageBox-aiView"> + <div className="imageBox-aiView-regenerate"> + <input + style={{ color: SnappingManager.userColor, background: SnappingManager.userBackgroundColor }} + className="imageBox-aiView-input" + aria-label="Edit instructions input" + type="text" + value={this._regenInput || StrCast(this.Document.title)} + onChange={action(e => this._canInteract && (this._regenInput = e.target.value))} + placeholder={this._regenInput || StrCast(this.Document.title)} + /> + <div className="imageBox-aiView-regenerate-createBtn"> + <Button + text="Create" + type={Type.TERT} + size={Size.XSMALL} + color={SnappingManager.userColor} + background={SnappingManager.userBackgroundColor} + // style={{ alignSelf: 'flex-end' }} + icon={this._regenerateLoading ? <ReactLoading type="spin" color={SettingsManager.userVariantColor} width={16} height={20} /> : <AiOutlineSend />} + iconPlacement="right" + onClick={action(() => { + this._regenerateLoading = true; + DrawingFillHandler.drawingToImage(this.Document, this._fireflyRefStrength, this._regenInput || StrCast(this.Document.title))?.then(action(() => (this._regenerateLoading = false))); + })} + /> + </div> + <div> + <NumberDropdown + color={SnappingManager.userColor} + background={SnappingManager.userBackgroundColor} + numberDropdownType="slider" + showPlusMinus={false} + formLabel="similarity" + tooltip="structure similarity of created images to current image" + type={Type.PRIM} + width={75} + min={0} + max={100} + number={this._fireflyRefStrength} + size={Size.XXSMALL} + setNumber={undoable( + action(val => this._canInteract && (this._fireflyRefStrength = val as number)), + `${this.Document.title} button set from list` + )} + fillWidth /> - <div className="collectionFreeFormView-aiView-strength"> - <span className="collectionFreeFormView-aiView-similarity">Similarity</span> - <Slider - className="collectionfreeformview-aiView-slider" - sx={{ - '& .MuiSlider-track': { color: SettingsManager.userVariantColor }, - '& .MuiSlider-rail': { color: SettingsManager.userBackgroundColor }, - '& .MuiSlider-thumb': { color: SettingsManager.userVariantColor, '&.Mui-focusVisible, &:hover, &.Mui-active': { boxShadow: `0px 0px 0px 8px${SettingsManager.userColor.slice(0, 7)}10` } }, - }} - min={1} - max={100} - step={1} - size="small" - value={this._fireflyRefStrength} - onChange={action((e, val) => (this._fireflyRefStrength = val as number))} - valueLabelDisplay="auto" - /> - </div> - <div className="collectionFreeFormView-aiView-send"> - <Button - text="Send" - type={Type.SEC} - icon={this._drawingFillLoading ? <ReactLoading type="spin" color={SettingsManager.userVariantColor} width={16} height={20} /> : <AiOutlineSend />} - iconPlacement="right" - onClick={undoable( - action(() => { - this._drawingFillLoading = true; - DrawingFillHandler.drawingToImage(this.props.Document, this._fireflyRefStrength, this._drawingFillInput || StrCast(this.Document.title))?.then(action(() => (this._drawingFillLoading = false))); - }), - 'create image' - )} - /> - </div> </div> </div> </div> diff --git a/src/client/views/pdf/PDFViewer.tsx b/src/client/views/pdf/PDFViewer.tsx index 1de945d69..6e8ce0ce9 100644 --- a/src/client/views/pdf/PDFViewer.tsx +++ b/src/client/views/pdf/PDFViewer.tsx @@ -163,25 +163,17 @@ export class PDFViewer extends ObservableReactComponent<IViewerProps> { }; @computed get _scrollHeight() { - return this._pageSizes.reduce((size, page) => size + page.height, 0); + return this._pageSizes.reduce((size, page) => size + page.height, 0) / window.devicePixelRatio; } initialLoad = () => { - const page0or180 = (page: { rotate: number }) => page.rotate === 0 || page.rotate === 180; if (this._pageSizes.length === 0) { const devicePixelRatio = window.devicePixelRatio; document.documentElement?.style.setProperty('--devicePixelRatio', window.devicePixelRatio.toString()); // set so that css can use this to adjust various PDFJs divs - Promise.all( - numberRange(this._props.pdf.numPages).map(i => - this._props.pdf.getPage(i + 1).then(page => ({ - width: (page.view[page0or180(page) ? 2 : 3] - page.view[page0or180(page) ? 0 : 1]) * devicePixelRatio, - height: (page.view[page0or180(page) ? 3 : 2] - page.view[page0or180(page) ? 1 : 0]) * devicePixelRatio, - })) - ) - ).then( + Promise.all(numberRange(this._props.pdf.numPages).map(i => this._props.pdf.getPage(i + 1).then(page => page.getViewport({ scale: devicePixelRatio })))).then( action(pages => { this._pageSizes = pages; - this._props.loaded(pages.lastElement(), this._props.pdf.numPages); + this._props.loaded(pages[0], this._props.pdf.numPages); this.createPdfViewer(); }) ); diff --git a/src/server/DashUploadUtils.ts b/src/server/DashUploadUtils.ts index f76371b0d..846a5fc82 100644 --- a/src/server/DashUploadUtils.ts +++ b/src/server/DashUploadUtils.ts @@ -16,14 +16,14 @@ import { basename } from 'path'; import * as parse from 'pdf-parse'; import * as request from 'request-promise'; import { Duplex, Stream } from 'stream'; +import { Worker, isMainThread, parentPort } from 'worker_threads'; import { Utils } from '../Utils'; +import requestImageSize from '../client/util/request-image-size'; import { createIfNotExists } from './ActionUtilities'; import { AzureManager } from './ApiManagers/AzureManager'; import { AcceptableMedia, Upload } from './SharedMediaTypes'; import { Directory, clientPathToFile, filesDirectory, pathToDirectory, publicDirectory, serverPathToFile } from './SocketData'; import { resolvedServerUrl } from './server_Initialization'; -import { Worker, isMainThread, parentPort } from 'worker_threads'; -import requestImageSize from '../client/util/request-image-size'; // Create an array to store worker threads enum workertasks { @@ -537,14 +537,14 @@ export namespace DashUploadUtils { } const dataBuffer = readFileSync(file.filepath); const result: parse.Result = await parse(dataBuffer).catch(e => e); - if (result) { + if (result?.text) { await new Promise<void>((resolve, reject) => { const writeStream = createWriteStream(serverPathToFile(Directory.text, textFilename)); - writeStream.write(result?.text, error => (error ? reject(error) : resolve())); + writeStream.write(result?.text ?? '', error => (error ? reject(error) : resolve())); }); return MoveParsedFile(file, Directory.pdfs, undefined, result?.text, undefined, fileKey); } - return { source: file, result: { name: 'faile pdf pupload', message: `Could not upload (${file.originalFilename}).${result}` } }; + return { source: file, result: { name: 'failed pdf upload', message: `Could not upload (${file.originalFilename}) ${result}` } }; } async function UploadCsv(file: File) { |