Skip to content

Commit

Permalink
base64 file content
Browse files Browse the repository at this point in the history
  • Loading branch information
Aniket-Engg committed Jan 25, 2024
1 parent a174870 commit 4835176
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 3 deletions.
13 changes: 13 additions & 0 deletions libs/remix-ui/workspace/src/lib/actions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,19 @@ export const copyFile = async (src: string, dest: string) => {
}
}

export const copyShareURL = async (path: string) => {
const fileManager = plugin.fileManager

try {
const fileContent = await fileManager.readFile(path)
console.log('fileContent------>', fileContent)
const base64Content = btoa(fileContent)
console.log('base64Content------>', base64Content)
} catch (error) {
dispatch(displayPopUp('Oops! An error ocurred while performing copyFile operation.' + error))
}
}

export const copyFolder = async (src: string, dest: string) => {
const fileManager = plugin.fileManager

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ export const FileExplorerContextMenu = (props: FileExplorerContextMenuProps) =>
copyPath(path, type)
_paq.push(['trackEvent', 'fileExplorer', 'contextMenu', 'copyPath'])
break
case 'Copy Share URL':
case 'Copy share URL':
copyShareURL(path, type)
_paq.push(['trackEvent', 'fileExplorer', 'contextMenu', 'copyShareURL'])
break
Expand Down
1 change: 1 addition & 0 deletions libs/remix-ui/workspace/src/lib/contexts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export const FileSystemContext = createContext<{
dispatchRenamePath: (oldPath: string, newPath: string) => Promise<void>,
dispatchDownloadPath: (path:string) => Promise<void>,
dispatchCopyFile: (src: string, dest: string) => Promise<void>,
dispatchCopyShareURL: (path: string) => Promise<void>,
dispatchCopyFolder: (src: string, dest: string) => Promise<void>,
dispatchRunScript: (path: string) => Promise<void>,
dispatchEmitContextMenuEvent: (cmd: customAction) => Promise<void>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
renamePath,
downloadPath,
copyFile,
copyShareURL,
copyFolder,
runScript,
emitContextMenuEvent,
Expand Down Expand Up @@ -156,6 +157,10 @@ export const FileSystemProvider = (props: WorkspaceProps) => {
await copyFile(src, dest)
}

const dispatchCopyShareURL = async (path: string) => {
await copyShareURL(path)
}

const dispatchCopyFolder = async (src: string, dest: string) => {
await copyFolder(src, dest)
}
Expand Down Expand Up @@ -352,6 +357,7 @@ export const FileSystemProvider = (props: WorkspaceProps) => {
dispatchRenamePath,
dispatchDownloadPath,
dispatchCopyFile,
dispatchCopyShareURL,
dispatchCopyFolder,
dispatchRunScript,
dispatchEmitContextMenuEvent,
Expand Down
6 changes: 4 additions & 2 deletions libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -536,8 +536,8 @@ export function Workspace() {

// eslint-disable-next-line @typescript-eslint/no-unused-vars
const handleCopyShareURLClick = (path: string, _type: string) => {
const fileName = extractNameFromKey(path)
console.log('handleCopyShareURLClick---->', fileName)
console.log('path---->', path)
global.dispatchCopyShareURL(path)
// navigator.clipboard.writeText(fileName)
}

Expand Down Expand Up @@ -1105,6 +1105,7 @@ export function Workspace() {
dispatchUploadFile={global.dispatchUploadFile}
dispatchUploadFolder={global.dispatchUploadFolder}
dispatchCopyFile={global.dispatchCopyFile}
dispatchCopyShareURL={global.dispatchCopyShareURL}
dispatchCopyFolder={global.dispatchCopyFolder}
dispatchPublishToGist={global.dispatchPublishToGist}
dispatchRunScript={global.dispatchRunScript}
Expand Down Expand Up @@ -1164,6 +1165,7 @@ export function Workspace() {
dispatchUploadFile={global.dispatchUploadFile}
dispatchUploadFolder={global.dispatchUploadFolder}
dispatchCopyFile={global.dispatchCopyFile}
dispatchCopyShareURL={global.dispatchCopyShareURL}
dispatchCopyFolder={global.dispatchCopyFolder}
dispatchPublishToGist={global.dispatchPublishToGist}
dispatchRunScript={global.dispatchRunScript}
Expand Down
1 change: 1 addition & 0 deletions libs/remix-ui/workspace/src/lib/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ export interface FileExplorerProps {
dispatchUploadFile: (target?: React.SyntheticEvent, targetFolder?: string) => Promise<void>,
dispatchUploadFolder: (target?: React.SyntheticEvent, targetFolder?: string) => Promise<void>,
dispatchCopyFile: (src: string, dest: string) => Promise<void>,
dispatchCopyShareURL: (path:string) => Promise<void>,
dispatchCopyFolder: (src: string, dest: string) => Promise<void>,
dispatchRunScript: (path: string) => Promise<void>,
dispatchPublishToGist: (path?: string, type?: string) => Promise<void>,
Expand Down

0 comments on commit 4835176

Please sign in to comment.