@@ -5,13 +5,16 @@ import fs from 'fs';
5
5
import { checkRemoteFileAccess , checkRemoteFileExists , getPodRoot } from "../utils/util" ;
6
6
import type { Logger } from '../logger' ;
7
7
import { ICommandOptions , setOptionDefaults } from './solid-command' ;
8
+ import touch from "./solid-touch" ;
9
+ const mime = require ( 'mime-types' ) ;
8
10
9
11
const md5 = require ( 'md5' ) ;
10
12
const child_process = require ( 'child_process' )
11
13
12
14
interface ICommandOptionsEdit extends ICommandOptions {
13
15
editor ?: string ,
14
16
touch ?: boolean ,
17
+ contentType ?: string ,
15
18
}
16
19
17
20
export default async function edit ( url : string , options ?: ICommandOptionsEdit ) {
@@ -26,7 +29,8 @@ export default async function edit(url: string, options?: ICommandOptionsEdit) {
26
29
if ( ! commandOptions . touch ) {
27
30
throw new Error ( 'Could not edit non-existing resource. Please use the --touch flag to create a new resource on edit.' )
28
31
}
29
- await editNewFile ( url , commandOptions )
32
+ await touch ( url , commandOptions ) ;
33
+ await editRemoteFile ( url , commandOptions )
30
34
} else {
31
35
throw new Error ( `No access rights for editing resource at ${ url } .` )
32
36
}
@@ -97,48 +101,6 @@ async function editRemoteFile(url: string, options: ICommandOptionsEdit) {
97
101
}
98
102
}
99
103
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
-
142
104
async function fileMD5 ( path : string ) {
143
105
return new Promise ( ( resolve , reject ) => {
144
106
fs . readFile ( path , ( err , buf ) => {
0 commit comments