mirror of
https://github.com/DustinBrett/daedalOS.git
synced 2025-12-06 00:20:05 +01:00
Access ipfs urls via Run/Terminal
This commit is contained in:
parent
ed56916e42
commit
516c5ccbd9
|
|
@ -117,6 +117,7 @@
|
|||
"shorthandLast": true
|
||||
}
|
||||
],
|
||||
"react/no-unknown-property": "off",
|
||||
"react/no-unused-prop-types": "error",
|
||||
"react/no-unused-state": "error",
|
||||
"react/require-default-props": "off",
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ import {
|
|||
} from "components/apps/Terminal/useTerminal";
|
||||
import extensions from "components/system/Files/FileEntry/extensions";
|
||||
import {
|
||||
getIpfsResource,
|
||||
getModifiedTime,
|
||||
getProcessByFileExtension,
|
||||
} from "components/system/Files/FileEntry/functions";
|
||||
|
|
@ -32,6 +33,7 @@ import processDirectory from "contexts/process/directory";
|
|||
import { basename, dirname, extname, isAbsolute, join } from "path";
|
||||
import { useCallback, useEffect, useRef } from "react";
|
||||
import {
|
||||
DESKTOP_PATH,
|
||||
HIGH_PRIORITY_REQUEST,
|
||||
isFileSystemSupported,
|
||||
ONE_DAY_IN_MILLISECONDS,
|
||||
|
|
@ -76,12 +78,27 @@ const useCommandInterpreter = (
|
|||
title: changeTitle,
|
||||
} = useProcesses();
|
||||
const getFullPath = useCallback(
|
||||
(file: string): string => {
|
||||
async (file: string): Promise<string> => {
|
||||
if (!file) return "";
|
||||
|
||||
if (file.startsWith("ipfs://")) {
|
||||
const ipfsFile = join(
|
||||
DESKTOP_PATH,
|
||||
await createPath(
|
||||
file.replace("ipfs://", "").split("/").filter(Boolean).join("_"),
|
||||
DESKTOP_PATH,
|
||||
await getIpfsResource(file)
|
||||
)
|
||||
);
|
||||
|
||||
updateFolder(DESKTOP_PATH, basename(ipfsFile));
|
||||
|
||||
return ipfsFile;
|
||||
}
|
||||
|
||||
return isAbsolute(file) ? file : join(cd.current, file);
|
||||
},
|
||||
[cd]
|
||||
[cd, createPath, updateFolder]
|
||||
);
|
||||
const colorOutput = useRef<string[]>([]);
|
||||
const updateFile = useCallback(
|
||||
|
|
@ -112,7 +129,7 @@ const useCommandInterpreter = (
|
|||
const [file] = commandArgs;
|
||||
|
||||
if (file) {
|
||||
const fullPath = getFullPath(file);
|
||||
const fullPath = await getFullPath(file);
|
||||
|
||||
if (await exists(fullPath)) {
|
||||
if ((await lstat(fullPath)).isDirectory()) {
|
||||
|
|
@ -134,7 +151,7 @@ const useCommandInterpreter = (
|
|||
const [directory] = commandArgs;
|
||||
|
||||
if (directory && lcBaseCommand !== "pwd") {
|
||||
const fullPath = getFullPath(directory);
|
||||
const fullPath = await getFullPath(directory);
|
||||
|
||||
if (await exists(fullPath)) {
|
||||
if (!(await lstat(fullPath)).isDirectory()) {
|
||||
|
|
@ -199,11 +216,11 @@ const useCommandInterpreter = (
|
|||
case "copy":
|
||||
case "cp": {
|
||||
const [source, destination] = commandArgs;
|
||||
const fullSourcePath = getFullPath(source);
|
||||
const fullSourcePath = await getFullPath(source);
|
||||
|
||||
if (await exists(fullSourcePath)) {
|
||||
if (destination) {
|
||||
const fullDestinationPath = getFullPath(destination);
|
||||
const fullDestinationPath = await getFullPath(destination);
|
||||
const dirName = dirname(fullDestinationPath);
|
||||
|
||||
updateFile(
|
||||
|
|
@ -245,7 +262,7 @@ const useCommandInterpreter = (
|
|||
const [commandPath] = commandArgs;
|
||||
|
||||
if (commandPath) {
|
||||
const fullPath = getFullPath(commandPath);
|
||||
const fullPath = await getFullPath(commandPath);
|
||||
|
||||
if (await exists(fullPath)) {
|
||||
await deletePath(fullPath);
|
||||
|
|
@ -334,7 +351,7 @@ const useCommandInterpreter = (
|
|||
!directory.startsWith("*") &&
|
||||
!directory.endsWith("*")
|
||||
) {
|
||||
const fullPath = getFullPath(directory);
|
||||
const fullPath = await getFullPath(directory);
|
||||
|
||||
if (await exists(fullPath)) {
|
||||
if ((await lstat(fullPath)).isDirectory()) {
|
||||
|
|
@ -361,7 +378,7 @@ const useCommandInterpreter = (
|
|||
const [commandPath] = commandArgs;
|
||||
|
||||
if (commandPath) {
|
||||
const fullPath = getFullPath(commandPath);
|
||||
const fullPath = await getFullPath(commandPath);
|
||||
|
||||
if (await exists(fullPath)) {
|
||||
const { fileTypeFromBuffer } = await import("file-type");
|
||||
|
|
@ -388,7 +405,7 @@ const useCommandInterpreter = (
|
|||
const [file, format] = commandArgs;
|
||||
|
||||
if (file && format) {
|
||||
const fullPath = getFullPath(file);
|
||||
const fullPath = await getFullPath(file);
|
||||
|
||||
if (
|
||||
(await exists(fullPath)) &&
|
||||
|
|
@ -484,7 +501,7 @@ const useCommandInterpreter = (
|
|||
const [directory] = commandArgs;
|
||||
|
||||
if (directory) {
|
||||
const fullPath = getFullPath(directory);
|
||||
const fullPath = await getFullPath(directory);
|
||||
|
||||
await mkdirRecursive(fullPath);
|
||||
updateFile(fullPath);
|
||||
|
|
@ -521,11 +538,11 @@ const useCommandInterpreter = (
|
|||
case "ren":
|
||||
case "rename": {
|
||||
const [source, destination] = commandArgs;
|
||||
const fullSourcePath = getFullPath(source);
|
||||
const fullSourcePath = await getFullPath(source);
|
||||
|
||||
if (await exists(fullSourcePath)) {
|
||||
if (destination) {
|
||||
const fullDestinationPath = getFullPath(destination);
|
||||
const fullDestinationPath = await getFullPath(destination);
|
||||
|
||||
await rename(fullSourcePath, fullDestinationPath);
|
||||
updateFile(fullSourcePath, true);
|
||||
|
|
@ -560,7 +577,7 @@ const useCommandInterpreter = (
|
|||
case "python": {
|
||||
if (localEcho) {
|
||||
const [file] = commandArgs;
|
||||
const fullSourcePath = getFullPath(file);
|
||||
const fullSourcePath = await getFullPath(file);
|
||||
|
||||
if (await exists(fullSourcePath)) {
|
||||
const code = await readFile(fullSourcePath);
|
||||
|
|
@ -592,7 +609,7 @@ const useCommandInterpreter = (
|
|||
const [file] = commandArgs;
|
||||
|
||||
if (file) {
|
||||
const fullPath = getFullPath(file);
|
||||
const fullPath = await getFullPath(file);
|
||||
const dirName = dirname(fullPath);
|
||||
|
||||
updateFile(
|
||||
|
|
@ -660,7 +677,7 @@ const useCommandInterpreter = (
|
|||
const [file, format = "xlsx"] = commandArgs;
|
||||
|
||||
if (file && format) {
|
||||
const fullPath = getFullPath(file);
|
||||
const fullPath = await getFullPath(file);
|
||||
|
||||
if (
|
||||
(await exists(fullPath)) &&
|
||||
|
|
@ -698,7 +715,7 @@ const useCommandInterpreter = (
|
|||
|
||||
if (pid) {
|
||||
const [file] = commandArgs;
|
||||
const fullPath = getFullPath(file);
|
||||
const fullPath = await getFullPath(file);
|
||||
|
||||
open(pid, {
|
||||
url:
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ import type { ComponentProcessProps } from "components/system/Apps/RenderCompone
|
|||
import StyledRun from "components/system/Dialogs/Run/StyledRun";
|
||||
import StyledButton from "components/system/Dialogs/Transfer/StyledButton";
|
||||
import {
|
||||
getIpfsResource,
|
||||
getProcessByFileExtension,
|
||||
getShortcutInfo,
|
||||
} from "components/system/Files/FileEntry/functions";
|
||||
|
|
@ -10,9 +11,10 @@ import { useFileSystem } from "contexts/fileSystem";
|
|||
import { useProcesses } from "contexts/process";
|
||||
import processDirectory from "contexts/process/directory";
|
||||
import { useSession } from "contexts/session";
|
||||
import { extname } from "path";
|
||||
import { basename, extname, join } from "path";
|
||||
import { useCallback, useLayoutEffect, useRef, useState } from "react";
|
||||
import {
|
||||
DESKTOP_PATH,
|
||||
PACKAGE_DATA,
|
||||
PREVENT_SCROLL,
|
||||
SHORTCUT_EXTENSION,
|
||||
|
|
@ -49,7 +51,7 @@ const Run: FC<ComponentProcessProps> = () => {
|
|||
closeWithTransition,
|
||||
processes: { Run: runProcess } = {},
|
||||
} = useProcesses();
|
||||
const { exists, readFile, stat } = useFileSystem();
|
||||
const { createPath, exists, readFile, stat, updateFolder } = useFileSystem();
|
||||
const { foregroundId, runHistory, setRunHistory } = useSession();
|
||||
const inputRef = useRef<HTMLInputElement | null>(null);
|
||||
const [isInputFocused, setIsInputFocused] = useState(true);
|
||||
|
|
@ -74,7 +76,25 @@ const Run: FC<ComponentProcessProps> = () => {
|
|||
resourceUrl.length > 0 ? resourceUrl.join(" ") : resourcePid;
|
||||
}
|
||||
|
||||
if (resourceExists || (await exists(resourcePath))) {
|
||||
const isIpfs = resourcePath.startsWith("ipfs://");
|
||||
|
||||
if (resourceExists || isIpfs || (await exists(resourcePath))) {
|
||||
if (isIpfs) {
|
||||
resourcePath = join(
|
||||
DESKTOP_PATH,
|
||||
await createPath(
|
||||
resourcePath
|
||||
.replace("ipfs://", "")
|
||||
.split("/")
|
||||
.filter(Boolean)
|
||||
.join("_"),
|
||||
DESKTOP_PATH,
|
||||
await getIpfsResource(resourcePath)
|
||||
)
|
||||
);
|
||||
updateFolder(DESKTOP_PATH, basename(resourcePath));
|
||||
}
|
||||
|
||||
const stats = await stat(resourcePath);
|
||||
|
||||
if (stats.isDirectory()) {
|
||||
|
|
@ -135,7 +155,16 @@ const Run: FC<ComponentProcessProps> = () => {
|
|||
|
||||
if (closeOnExecute) closeWithTransition("Run");
|
||||
},
|
||||
[closeWithTransition, exists, open, readFile, setRunHistory, stat]
|
||||
[
|
||||
closeWithTransition,
|
||||
createPath,
|
||||
exists,
|
||||
open,
|
||||
readFile,
|
||||
setRunHistory,
|
||||
stat,
|
||||
updateFolder,
|
||||
]
|
||||
);
|
||||
|
||||
useLayoutEffect(() => {
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ import {
|
|||
ICON_GIF_FPS,
|
||||
ICON_GIF_SECONDS,
|
||||
IMAGE_FILE_EXTENSIONS,
|
||||
IPFS_GATEWAY_URL,
|
||||
MOUNTED_FOLDER_ICON,
|
||||
MP3_MIME_TYPE,
|
||||
NEW_FOLDER_ICON,
|
||||
|
|
@ -584,3 +585,9 @@ export const getTextWrapData = (
|
|||
width: Math.min(maxWidth, totalWidth),
|
||||
};
|
||||
};
|
||||
|
||||
export const getIpfsResource = async (ipfsUrl: string): Promise<Buffer> => {
|
||||
const response = await fetch(ipfsUrl.replace("ipfs://", IPFS_GATEWAY_URL));
|
||||
|
||||
return Buffer.from(await response.arrayBuffer());
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user