WIP symlink, net_device virtio, move fixes, upload binary fixes

This commit is contained in:
ProgrammerIn-wonderland 2024-10-21 17:00:28 -04:00 committed by Eric Dubé
parent 13248a99bf
commit 891e799e5e
6 changed files with 78 additions and 5 deletions

View File

@ -326,8 +326,10 @@ window.onload = async function()
},
// bzimage_initrd_from_filesystem: true,
autostart: true,
network_relay_url: emu_config.network_relay ?? "wisp://127.0.0.1:4000",
net_device: {
relay_url: emu_config.network_relay ?? "wisp://127.0.0.1:4000",
type: "virtio"
},
virtio_console: true,
});

View File

@ -10,6 +10,7 @@ import read from "./operations/read.js";
import move from "./operations/move.js";
import write from "./operations/write.js";
import sign from "./operations/sign.js";
import symlink from './operations/symlink.js';
// Why is this called deleteFSEntry instead of just delete? because delete is
// a reserved keyword in javascript
import deleteFSEntry from "./operations/deleteFSEntry.js";
@ -32,6 +33,7 @@ export class PuterJSFileSystemModule extends AdvancedBase {
move = move;
write = write;
sign = sign;
symlink = symlink;
static NARI_METHODS = {
stat: {

View File

@ -1,9 +1,10 @@
import * as utils from '../../../lib/utils.js';
import getAbsolutePathForApp from '../utils/getAbsolutePathForApp.js';
import stat from "./stat.js"
import path from "../../../lib/path.js"
const move = function (...args) {
let options;
// If first argument is an object, it's the options
if (typeof args[0] === 'object' && args[0] !== null) {
options = args[0];
@ -36,6 +37,19 @@ const move = function (...args) {
options.source = getAbsolutePathForApp(options.source);
options.destination = getAbsolutePathForApp(options.destination);
if (!options.new_name) {
// Handler to check if dest is supposed to be a file or a folder
try {
const destStats = await stat.bind(this)(options.destination); // this is meant to error if it doesn't exist
if (!destStats.is_dir) {
throw "is not directory" // just a wuick way to just to the catch
}
} catch (e) {
options.new_name = path.basename(options.destination);
options.destination = path.dirname(options.destination);
}
}
// create xhr object
const xhr = utils.initXhr('/move', this.APIOrigin, this.authToken);

View File

@ -0,0 +1,55 @@
import getAbsolutePathForApp from '../utils/getAbsolutePathForApp.js';
import pathLib from '../../../lib/path.js';
// This only works for absolute symlinks for now
const symlink = async function (target, linkPath) {
// If auth token is not provided and we are in the web environment,
// try to authenticate with Puter
if(!puter.authToken && puter.env === 'web'){
try{
await puter.ui.authenticateWithPuter();
}catch(e){
// if authentication fails, throw an error
throw 'Authentication failed.';
}
}
// convert path to absolute path
linkPath = getAbsolutePathForApp(linkPath);
target = getAbsolutePathForApp(target);
const name = pathLib.basename(linkPath);
const linkDir = pathLib.dirname(linkPath)
const op =
{
op: 'symlink',
path: linkDir,
name: name,
target: target
};
const formData = new FormData();
formData.append('operation', JSON.stringify(op));
try {
const response = await fetch(this.APIOrigin + "/batch", {
method: 'POST',
headers: { 'Authorization': `Bearer ${puter.authToken}` },
body: formData
});
if (response.status !== 200) {
const error = await response.text();
console.error("[symlink] fetch error: ", error);
throw error;
}
} catch (e) {
console.error("[symlink] fetch error: ", e);
throw e;
}
}
export default symlink;

View File

@ -104,7 +104,7 @@ const upload = async function(items, dirPath, options = {}){
// blob
else if(items instanceof Blob){
// create a File object from the blob
let file = new File([items], options.name, { type: "text/plain" });
let file = new File([items], options.name, { type: "application/octet-stream" });
entries = [file];
// add FullPath property to each entry
for(let i=0; i<entries.length; i++){

@ -1 +1 @@
Subproject commit a4b34ab471e31014a56a7467bfcd51a066de37e5
Subproject commit d9c36dfccface164a34e20a7f44658fc5b7a6cc0