Convert all file ops to use absolute paths
This commit is contained in:
@@ -198,6 +198,7 @@ class DialogEx extends React.Component<DialogExProps,DialogExState> implements I
|
||||
{
|
||||
this.onEnterKey();
|
||||
}
|
||||
evt.stopPropagation();
|
||||
}
|
||||
render() {
|
||||
let { tag,onClose,...extra} = this.props;
|
||||
|
||||
@@ -741,9 +741,7 @@ export default withStyles(styles, { withTheme: true })(
|
||||
}
|
||||
}
|
||||
uploadPage={
|
||||
"uploadUserFile?directory=" + encodeURIComponent(
|
||||
pathConcat(this.props.fileProperty.directory, this.state.navDirectory)
|
||||
)
|
||||
"uploadUserFile?directory=" + encodeURIComponent(this.state.navDirectory)
|
||||
+ "&ext="
|
||||
+ encodeURIComponent(this.getFileExtensionList(this.props.fileProperty))
|
||||
}
|
||||
@@ -792,7 +790,7 @@ export default withStyles(styles, { withTheme: true })(
|
||||
defaultPath={this.getDefaultPath()}
|
||||
excludeDirectory={
|
||||
this.isDirectory(this.state.selectedFile)
|
||||
? pathConcat(this.state.navDirectory, pathFileName(this.state.selectedFile)) : ""}
|
||||
? this.state.selectedFile : ""}
|
||||
onClose={() => { this.setState({ moveDialogOpen: false }); }}
|
||||
onOk={
|
||||
(path) => {
|
||||
|
||||
@@ -38,28 +38,18 @@ import { isDarkMode } from './DarkMode';
|
||||
import IconButton from '@mui/material/IconButton';
|
||||
|
||||
|
||||
function pathConcat(l: string, r: string): string
|
||||
{
|
||||
if (l.length === 0) return r;
|
||||
if (r.length === 0) return l;
|
||||
return l +'/' + r;
|
||||
}
|
||||
|
||||
class DirectoryTree {
|
||||
name: string = "";
|
||||
path: string = "";
|
||||
expanded: boolean = false;
|
||||
isProtected: boolean = true;
|
||||
children: DirectoryTree[] = [];
|
||||
|
||||
constructor(tree: FilePropertyDirectoryTree, parentTree: (DirectoryTree | null) = null) {
|
||||
this.name = tree.directoryName;
|
||||
if (parentTree) {
|
||||
this.path = pathConcat(parentTree.path,tree.directoryName);
|
||||
} else {
|
||||
this.name = "Home";
|
||||
this.path = tree.directoryName;
|
||||
this.expanded = true;
|
||||
}
|
||||
this.path = tree.directoryName;
|
||||
this.name = tree.displayName;
|
||||
this.isProtected = tree.isProtected;
|
||||
for (var treeChild of tree.children) {
|
||||
this.children.push(new DirectoryTree(treeChild, this));
|
||||
}
|
||||
@@ -143,6 +133,7 @@ export interface FilePropertyDirectorySelectDialogState {
|
||||
selectedPath: string;
|
||||
directoryTree?: DirectoryTree;
|
||||
hasSelection: boolean;
|
||||
isProtected: boolean;
|
||||
directoryTreeInvalidatecount: number;
|
||||
|
||||
};
|
||||
@@ -160,6 +151,7 @@ export default class FilePropertyDirectorySelectDialog extends ResizeResponsiveC
|
||||
selectedPath: props.defaultPath,
|
||||
directoryTree: undefined,
|
||||
hasSelection: false,
|
||||
isProtected: true,
|
||||
directoryTreeInvalidatecount: 0
|
||||
|
||||
};
|
||||
@@ -192,14 +184,19 @@ export default class FilePropertyDirectorySelectDialog extends ResizeResponsiveC
|
||||
this.model.getFilePropertyDirectoryTree(this.props.uiFileProperty)
|
||||
.then((filePropertyDirectoryTree) => {
|
||||
let myTree = new DirectoryTree(filePropertyDirectoryTree);
|
||||
if (this.props.excludeDirectory)
|
||||
if (this.props.excludeDirectory.length !== 0)
|
||||
{
|
||||
myTree.remove(this.props.excludeDirectory);
|
||||
}
|
||||
myTree.expand(this.state.selectedPath);
|
||||
|
||||
let hasSelection = myTree.find(this.state.selectedPath) != null;
|
||||
this.setState({ directoryTree: myTree, hasSelection: hasSelection });
|
||||
let selection = myTree.find(this.state.selectedPath);
|
||||
let hasSelection = !!selection;
|
||||
this.setState({
|
||||
directoryTree: myTree,
|
||||
hasSelection: hasSelection,
|
||||
isProtected: selection ? selection.isProtected : false
|
||||
});
|
||||
this.requestScroll = true;
|
||||
})
|
||||
.catch((e) => {
|
||||
@@ -223,6 +220,9 @@ export default class FilePropertyDirectorySelectDialog extends ResizeResponsiveC
|
||||
|
||||
|
||||
onOK() {
|
||||
if (this.state.isProtected) {
|
||||
return;
|
||||
}
|
||||
if (this.state.hasSelection) {
|
||||
this.props.onOk(this.state.selectedPath);
|
||||
}
|
||||
@@ -238,7 +238,11 @@ export default class FilePropertyDirectorySelectDialog extends ResizeResponsiveC
|
||||
private onTreeClick(directoryTree: DirectoryTree) {
|
||||
if (!this.state.directoryTree) return;
|
||||
this.state.directoryTree.expand(directoryTree.path);
|
||||
this.setState({ selectedPath: directoryTree.path, hasSelection: true, directoryTreeInvalidatecount: this.state.directoryTreeInvalidatecount + 1 });
|
||||
this.setState({
|
||||
selectedPath: directoryTree.path,
|
||||
hasSelection: true,
|
||||
isProtected: directoryTree.isProtected,
|
||||
directoryTreeInvalidatecount: this.state.directoryTreeInvalidatecount + 1 });
|
||||
}
|
||||
private renderTree_(directoryTree: DirectoryTree) {
|
||||
let ref: ((element: HTMLButtonElement | null) => void) | undefined = undefined;
|
||||
@@ -338,7 +342,8 @@ export default class FilePropertyDirectorySelectDialog extends ResizeResponsiveC
|
||||
<Button variant="dialogSecondary" onClick={() => { this.onClose(); }} color="primary">
|
||||
Cancel
|
||||
</Button>
|
||||
<Button variant="dialogPrimary" onClick={() => { this.onOK(); }} color="secondary" disabled={!this.state.hasSelection} >
|
||||
<Button variant="dialogPrimary" onClick={() => { this.onOK(); }} color="secondary"
|
||||
disabled={(!this.state.hasSelection) || this.state.isProtected} >
|
||||
OK
|
||||
</Button>
|
||||
</DialogActions>
|
||||
|
||||
@@ -21,6 +21,8 @@
|
||||
export default class FilePropertyDirectoryTree {
|
||||
deserialize(input: any) : FilePropertyDirectoryTree {
|
||||
this.directoryName = input.directoryName;
|
||||
this.displayName = input.displayName;
|
||||
this.isProtected = input.isProtected;
|
||||
this.children = FilePropertyDirectoryTree.deserialize_array(input.children);
|
||||
return this;
|
||||
}
|
||||
@@ -35,5 +37,7 @@ export default class FilePropertyDirectoryTree {
|
||||
|
||||
|
||||
directoryName: string = "";
|
||||
displayName: string = "";
|
||||
isProtected: boolean = false;
|
||||
children: FilePropertyDirectoryTree[] = [];
|
||||
}
|
||||
@@ -2510,7 +2510,7 @@ export class PiPedalModel //implements PiPedalModel
|
||||
link.click();
|
||||
}
|
||||
|
||||
uploadFile(uploadPage: string, file: File, contentType: string = "application/octet-stream", abortController?: AbortController): Promise<string> {
|
||||
uploadUserFile(uploadPage: string, file: File, contentType: string = "application/octet-stream", abortController?: AbortController): Promise<string> {
|
||||
let result = new Promise<string>((resolve, reject) => {
|
||||
try {
|
||||
if (file.size > this.maxFileUploadSize) {
|
||||
@@ -2551,10 +2551,20 @@ export class PiPedalModel //implements PiPedalModel
|
||||
}
|
||||
})
|
||||
.then((json) => {
|
||||
resolve(json as string);
|
||||
let response = json as {errorMessage: string, path: string};
|
||||
if (response.errorMessage !== "")
|
||||
{
|
||||
throw new Error(response.errorMessage);
|
||||
}
|
||||
resolve(response.path);
|
||||
})
|
||||
.catch((error) => {
|
||||
reject("Upload failed. " + error);
|
||||
if (error instanceof Error)
|
||||
{
|
||||
reject("Upload failed. " + (error as Error).message);
|
||||
} else {
|
||||
reject("Upload failed. " + error);
|
||||
}
|
||||
})
|
||||
;
|
||||
} catch (error) {
|
||||
|
||||
@@ -208,7 +208,7 @@ export default class UploadFileDialog extends ResizeResponsiveComponent<UploadFi
|
||||
{
|
||||
throw new Error("Invalid file extension.");
|
||||
}
|
||||
let filename = await this.model.uploadFile(
|
||||
let filename = await this.model.uploadUserFile(
|
||||
this.props.uploadPage,
|
||||
this.uploadList[i].file,
|
||||
"application/octet-stream",
|
||||
|
||||
Reference in New Issue
Block a user