mirror of
https://github.com/wavetermdev/waveterm
synced 2026-05-24 09:18:27 +00:00
Extra Mimetypes (#17)
Vastly expands the list of mimetypes we can detect from file extensions.
This commit is contained in:
parent
29e209e0b0
commit
2f2ff8a1cb
5 changed files with 1233 additions and 11 deletions
|
|
@ -57,7 +57,12 @@ function defaultEditorOptions(): MonacoTypes.editor.IEditorOptions {
|
|||
return opts;
|
||||
}
|
||||
|
||||
export function CodeEdit() {
|
||||
interface CodeEditProps {
|
||||
readonly: boolean;
|
||||
text: string;
|
||||
}
|
||||
|
||||
export function CodeEdit({ readonly, text }: CodeEditProps) {
|
||||
const divRef = React.useRef<HTMLDivElement>(null);
|
||||
const monacoRef = React.useRef<MonacoTypes.editor.IStandaloneCodeEditor | null>(null);
|
||||
const theme = "wave-theme-dark";
|
||||
|
|
@ -83,8 +88,8 @@ export function CodeEdit() {
|
|||
// TODO
|
||||
}
|
||||
|
||||
const text = "Hello, world!";
|
||||
const editorOpts = defaultEditorOptions();
|
||||
editorOpts.readOnly = readonly;
|
||||
|
||||
return (
|
||||
<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 (
|
||||
<div className="view-codeedit">
|
||||
<CodeEdit />
|
||||
<CodeEdit readonly={readonly} text={text} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ import * as util from "@/util/util";
|
|||
import clsx from "clsx";
|
||||
import * as jotai from "jotai";
|
||||
import { CenteredDiv } from "../element/quickelems";
|
||||
import { CodeEditView } from "./codeedit";
|
||||
import { DirectoryPreview } from "./directorypreview";
|
||||
|
||||
import "./view.less";
|
||||
|
|
@ -179,6 +180,11 @@ function PreviewView({ blockId }: { blockId: string }) {
|
|||
<pre>{fileContent}</pre>
|
||||
</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") {
|
||||
specializedView = <DirectoryPreview contentAtom={fileContentAtom} fileNameAtom={fileNameAtom} />;
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ type FileInfo struct {
|
|||
|
||||
type FullFile struct {
|
||||
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) {
|
||||
|
|
|
|||
1212
pkg/util/utilfn/mimetypes.go
Normal file
1212
pkg/util/utilfn/mimetypes.go
Normal file
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 ""
|
||||
// does not return "application/octet-stream" as this is considered a detection failure
|
||||
func DetectMimeType(path string) string {
|
||||
|
|
|
|||
Loading…
Reference in a new issue