@@ -5,13 +5,16 @@ import fs from 'fs';
55import { checkRemoteFileAccess , checkRemoteFileExists , getPodRoot } from "../utils/util" ;
66import type { Logger } from '../logger' ;
77import { ICommandOptions , setOptionDefaults } from './solid-command' ;
8+ import touch from "./solid-touch" ;
9+ const mime = require ( 'mime-types' ) ;
810
911const md5 = require ( 'md5' ) ;
1012const child_process = require ( 'child_process' )
1113
1214interface ICommandOptionsEdit extends ICommandOptions {
1315 editor ?: string ,
1416 touch ?: boolean ,
17+ contentType ?: string ,
1518}
1619
1720export default async function edit ( url : string , options ?: ICommandOptionsEdit ) {
@@ -26,7 +29,8 @@ export default async function edit(url: string, options?: ICommandOptionsEdit) {
2629 if ( ! commandOptions . touch ) {
2730 throw new Error ( 'Could not edit non-existing resource. Please use the --touch flag to create a new resource on edit.' )
2831 }
29- await editNewFile ( url , commandOptions )
32+ await touch ( url , commandOptions ) ;
33+ await editRemoteFile ( url , commandOptions )
3034 } else {
3135 throw new Error ( `No access rights for editing resource at ${ url } .` )
3236 }
@@ -97,48 +101,6 @@ async function editRemoteFile(url: string, options: ICommandOptionsEdit) {
97101 }
98102}
99103
100- async function editNewFile ( url : string , options : ICommandOptionsEdit ) {
101- const systemTmpDir = os . tmpdir ( )
102- const solidTmpDir = path . join ( systemTmpDir , '.solid/' )
103- let filename = url . split ( '/' ) . reverse ( ) [ 0 ]
104- const getRandomizedPrefix = ( ) => ( Math . random ( ) + 1 ) . toString ( 36 ) . substring ( 7 ) ;
105- filename = getRandomizedPrefix ( ) + "-" + filename
106-
107- let tmpFilePath : string | undefined ;
108- try {
109- let tmpFilePath = path . join ( solidTmpDir , filename ) ;
110- fs . writeFileSync ( tmpFilePath , "" )
111-
112- await new Promise < void > ( ( resolve , reject ) => {
113- var child = child_process . spawn ( options . editor , [ tmpFilePath ] , {
114- stdio : 'inherit'
115- } ) ;
116-
117- child . on ( 'exit' , function ( e : any , code : any ) {
118- resolve ( ) ;
119- } ) ;
120- } ) ;
121-
122- // Wait for the user to finish editing the
123- ( options . logger || console ) . log ( 'Press any key to continue' ) ;
124- await new Promise < void > ( ( resolve , reject ) => {
125- process . stdin . setRawMode ( true ) ;
126- process . stdin . resume ( ) ;
127- process . stdin . on ( 'data' , ( ) => resolve ( ) ) ;
128- } )
129-
130- await copy ( tmpFilePath , url , options )
131- if ( options . verbose ) ( options . logger || console ) . log ( 'Remote file updated!' ) ;
132- } catch ( e ) {
133- throw e
134- // TODO::
135- } finally {
136- if ( tmpFilePath ) fs . unlinkSync ( tmpFilePath ) ;
137- if ( options . verbose ) ( options . logger || console ) . log ( `Removing local file file ${ tmpFilePath } !` ) ;
138- }
139- }
140-
141-
142104async function fileMD5 ( path : string ) {
143105 return new Promise ( ( resolve , reject ) => {
144106 fs . readFile ( path , ( err , buf ) => {
0 commit comments