-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b2f2d65
commit acea402
Showing
7 changed files
with
117 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import vscode from 'vscode' | ||
import { OSSObjectTreeItem } from '@/views/bucket' | ||
import { ext } from '@/extensionVariables' | ||
import { CommandContext } from '@/constant' | ||
import { copyUri } from '@/uploader/copyUri' | ||
import Logger from '@/utils/log' | ||
import { removeLeadingSlash } from '@/utils' | ||
|
||
async function copyFromBucketExplorerContext( | ||
treeItem: OSSObjectTreeItem | ||
): Promise<void> { | ||
const sourceUri = vscode.Uri.parse(treeItem.url) | ||
const targetName = await vscode.window.showInputBox({ | ||
value: removeLeadingSlash(sourceUri.path), | ||
placeHolder: `Enter target name. e.g., 'example/folder/name/target.jpg'`, | ||
validateInput: (text) => { | ||
text = text.trim() | ||
if (text[0] === '/') return `Please do not start with '/'.` | ||
if (text === '') return `Please enter target name.` | ||
} | ||
}) | ||
if (!targetName) return | ||
try { | ||
await copyUri(vscode.Uri.file(targetName), sourceUri) | ||
} catch { | ||
Logger.log('catch function copyUri error') | ||
} | ||
|
||
ext.bucketExplorer.refresh() | ||
} | ||
// eslint-disable-next-line @typescript-eslint/no-namespace | ||
namespace copyFromBucketExplorerContext { | ||
export const command = CommandContext.BUCKET_EXPLORER_COPY_CONTEXT | ||
} | ||
|
||
export { copyFromBucketExplorerContext } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import Uploader from './index' | ||
import { getProgress, removeLeadingSlash, Progress } from '@/utils' | ||
import vscode from 'vscode' | ||
import Logger from '@/utils/log' | ||
|
||
export async function copyUri( | ||
targetUri: vscode.Uri, | ||
sourceUri: vscode.Uri, | ||
showProgress = true | ||
): Promise<void> { | ||
const uploader = Uploader.get() | ||
// init OSS instance failed | ||
if (!uploader) return | ||
|
||
// path '/ex/path', the 'ex' means source bucket name, should remove leading slash | ||
const sourceName = removeLeadingSlash(sourceUri.path) | ||
// leading slash of targetName is irrelevant | ||
const targetName = removeLeadingSlash(targetUri.path) | ||
|
||
let progress: Progress['progress'] | undefined | ||
let progressResolve: Progress['progressResolve'] | undefined | ||
if (showProgress) { | ||
const p = getProgress(`Copying image`) | ||
progress = p.progress | ||
progressResolve = p.progressResolve | ||
} | ||
try { | ||
await uploader.copy(targetName, sourceName) | ||
if (progress && progressResolve) { | ||
progress.report({ | ||
message: `Finish.`, | ||
increment: 100 | ||
}) | ||
;((fn): void => { | ||
setTimeout(() => { | ||
fn() | ||
}, 1000) | ||
})(progressResolve) | ||
} | ||
} catch (err) { | ||
progressResolve && progressResolve() | ||
Logger.showErrorMessage( | ||
`Failed to copy image. See output channel for more details` | ||
) | ||
Logger.log( | ||
`Failed: copy from ${sourceName} to ${targetName}.` + | ||
` Reason: ${err.message}` | ||
) | ||
throw err | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters