mirror of
https://github.com/wavetermdev/backup.git
synced 2026-08-05 13:57:07 -07:00
Extra Mimetypes (#17)
Vastly expands the list of mimetypes we can detect from file extensions.
This commit is contained in:
@@ -57,7 +57,12 @@ function defaultEditorOptions(): MonacoTypes.editor.IEditorOptions {
|
|||||||
return opts;
|
return opts;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function CodeEdit() {
|
interface CodeEditProps {
|
||||||
|
readonly: boolean;
|
||||||
|
text: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function CodeEdit({ readonly, text }: CodeEditProps) {
|
||||||
const divRef = React.useRef<HTMLDivElement>(null);
|
const divRef = React.useRef<HTMLDivElement>(null);
|
||||||
const monacoRef = React.useRef<MonacoTypes.editor.IStandaloneCodeEditor | null>(null);
|
const monacoRef = React.useRef<MonacoTypes.editor.IStandaloneCodeEditor | null>(null);
|
||||||
const theme = "wave-theme-dark";
|
const theme = "wave-theme-dark";
|
||||||
@@ -83,8 +88,8 @@ export function CodeEdit() {
|
|||||||
// TODO
|
// TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
const text = "Hello, world!";
|
|
||||||
const editorOpts = defaultEditorOptions();
|
const editorOpts = defaultEditorOptions();
|
||||||
|
editorOpts.readOnly = readonly;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="codeedit" ref={divRef}>
|
<div className="codeedit" ref={divRef}>
|
||||||
@@ -103,10 +108,15 @@ export function CodeEdit() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function CodeEditView() {
|
interface CodeEditViewProps {
|
||||||
|
readonly?: boolean;
|
||||||
|
text: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function CodeEditView({ readonly = false, text }: CodeEditViewProps) {
|
||||||
return (
|
return (
|
||||||
<div className="view-codeedit">
|
<div className="view-codeedit">
|
||||||
<CodeEdit />
|
<CodeEdit readonly={readonly} text={text} />
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import * as util from "@/util/util";
|
|||||||
import clsx from "clsx";
|
import clsx from "clsx";
|
||||||
import * as jotai from "jotai";
|
import * as jotai from "jotai";
|
||||||
import { CenteredDiv } from "../element/quickelems";
|
import { CenteredDiv } from "../element/quickelems";
|
||||||
|
import { CodeEditView } from "./codeedit";
|
||||||
import { DirectoryPreview } from "./directorypreview";
|
import { DirectoryPreview } from "./directorypreview";
|
||||||
|
|
||||||
import "./view.less";
|
import "./view.less";
|
||||||
@@ -179,6 +180,11 @@ function PreviewView({ blockId }: { blockId: string }) {
|
|||||||
<pre>{fileContent}</pre>
|
<pre>{fileContent}</pre>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
} else if (
|
||||||
|
mimeType.startsWith("application") &&
|
||||||
|
(mimeType.includes("json") || mimeType.includes("yaml") || mimeType.includes("toml"))
|
||||||
|
) {
|
||||||
|
specializedView = <CodeEditView readonly={true} text={fileContent} />;
|
||||||
} else if (mimeType === "directory") {
|
} else if (mimeType === "directory") {
|
||||||
specializedView = <DirectoryPreview contentAtom={fileContentAtom} fileNameAtom={fileNameAtom} />;
|
specializedView = <DirectoryPreview contentAtom={fileContentAtom} fileNameAtom={fileNameAtom} />;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ type FileInfo struct {
|
|||||||
|
|
||||||
type FullFile struct {
|
type FullFile struct {
|
||||||
Info *FileInfo `json:"info"`
|
Info *FileInfo `json:"info"`
|
||||||
Data64 string `json:"data64,omitempty"` // base64 encoded
|
Data64 string `json:"data64"` // base64 encoded
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fs *FileService) StatFile(path string) (*FileInfo, error) {
|
func (fs *FileService) StatFile(path string) (*FileInfo, error) {
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -618,12 +618,6 @@ func CopyToChannel(outputCh chan<- []byte, reader io.Reader) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO more
|
|
||||||
var StaticMimeTypeMap = map[string]string{
|
|
||||||
".md": "text/markdown",
|
|
||||||
".json": "application/json",
|
|
||||||
}
|
|
||||||
|
|
||||||
// on error just returns ""
|
// on error just returns ""
|
||||||
// does not return "application/octet-stream" as this is considered a detection failure
|
// does not return "application/octet-stream" as this is considered a detection failure
|
||||||
func DetectMimeType(path string) string {
|
func DetectMimeType(path string) string {
|
||||||
|
|||||||
Reference in New Issue
Block a user