Added directory/file exists
This commit is contained in:
22
src/index.js
22
src/index.js
@@ -13,6 +13,17 @@ export const create_api = (conn) => {
|
||||
return {
|
||||
directory: {
|
||||
create: async (remote_path) => ops.create_directory(conn, remote_path),
|
||||
exists: async (remote_path) => {
|
||||
try {
|
||||
const info = await ops.get_file_attributes2(conn, remote_path);
|
||||
return info.directory;
|
||||
} catch (e) {
|
||||
if (e.message.split(':')[1].trim() == '-2') {
|
||||
return false;
|
||||
}
|
||||
throw new Error(e.message);
|
||||
}
|
||||
},
|
||||
list: async (remote_path, page_reader_cb) =>
|
||||
ops.list_directory(conn, remote_path, page_reader_cb),
|
||||
remove: async (remote_path) => ops.remove_directory(conn, remote_path),
|
||||
@@ -43,6 +54,17 @@ export const create_api = (conn) => {
|
||||
overwrite,
|
||||
resume
|
||||
),
|
||||
exists: async (remote_path) => {
|
||||
try {
|
||||
const info = await ops.get_file_attributes2(conn, remote_path);
|
||||
return !info.directory;
|
||||
} catch (e) {
|
||||
if (e.message.split(':')[1].trim() == '-2') {
|
||||
return false;
|
||||
}
|
||||
throw new Error(e.message);
|
||||
}
|
||||
},
|
||||
open: async (remote_path) =>
|
||||
new file(conn, await ops.open_file(conn, remote_path), remote_path),
|
||||
upload: async (local_path, remote_path, progress_cb, overwrite, resume) =>
|
||||
|
||||
Reference in New Issue
Block a user