-
Notifications
You must be signed in to change notification settings - Fork 3.9k
adding needed changes #18987
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
adding needed changes #18987
Changes from all commits
23e7dcc
1515dfa
28259c7
4befca5
0028da0
781b6e5
8dcf282
7d07748
386fd57
ab363f7
c4faec4
f04bf18
a1a172d
b09aba8
2eed5d3
cf801b7
5864a67
478413d
48088f7
9464c0f
0e09f27
ca4a1c5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,14 +2,18 @@ import { getPreferenceValues } from "@raycast/api"; | |
import os from "os"; | ||
import path from "path"; | ||
|
||
export const DEFAULT_EXPORT_DIR_PATH = (): string => { | ||
const exportPath = getPreferenceValues().exportPath || path.join(process.env.HOME || "", "Documents", "ente"); | ||
let cachedExportDirPath: string; | ||
|
||
if (exportPath.startsWith("~/")) { | ||
return exportPath.replace("~", os.homedir()); | ||
export const DEFAULT_EXPORT_DIR_PATH = (): string => { | ||
if (cachedExportDirPath) { | ||
return cachedExportDirPath; | ||
} | ||
|
||
return exportPath; | ||
const exportPath = getPreferenceValues().exportPath || path.join(os.homedir(), "Documents", "ente"); | ||
|
||
cachedExportDirPath = exportPath.startsWith("~/") ? exportPath.replace("~", os.homedir()) : exportPath; | ||
|
||
return cachedExportDirPath; | ||
}; | ||
|
||
export const EXPORT_FILE_PATH = `${DEFAULT_EXPORT_DIR_PATH()}/ente_auth.txt`; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. style: DEFAULT_EXPORT_DIR_PATH() is called on every reference - consider memoizing the result |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
export const LINE_BREAK = "\n\n"; | ||
export const stripServiceName = (serviceName: string) => serviceName.replace(/-/g, "_").toLowerCase(); | ||
export const stripServiceName = (serviceName: string) => serviceName.replace(/-| /g, "").toLowerCase(); |
Original file line number | Diff line number | Diff line change | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,4 +1,5 @@ | ||||||||||||||||
import { Detail, showToast, Toast } from "@raycast/api"; | ||||||||||||||||
import { Detail } from "@raycast/api"; | ||||||||||||||||
import { showFailureToast } from "@raycast/utils"; | ||||||||||||||||
import { showError } from "./components/showError"; | ||||||||||||||||
import { DEFAULT_EXPORT_DIR_PATH, EXPORT_FILE_PATH } from "./constants/ente"; | ||||||||||||||||
import { checkEnteBinary, createEntePath, exportEnteAuthSecrets } from "./helpers/ente"; | ||||||||||||||||
|
@@ -14,14 +15,14 @@ export default function Command() { | |||||||||||||||
try { | ||||||||||||||||
createEntePath(DEFAULT_EXPORT_DIR_PATH()); | ||||||||||||||||
} catch (error) { | ||||||||||||||||
showToast(Toast.Style.Failure, "Folder creation failed"); | ||||||||||||||||
return <Detail markdown={`## Failed to create folder at \`${DEFAULT_EXPORT_DIR_PATH}\``} />; | ||||||||||||||||
showFailureToast(error, { title: "Folder creation failed" }); | ||||||||||||||||
return <Detail markdown={`## Failed to create folder at \`${DEFAULT_EXPORT_DIR_PATH()}\``} />; | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
try { | ||||||||||||||||
exportEnteAuthSecrets(); | ||||||||||||||||
} catch (error) { | ||||||||||||||||
showToast(Toast.Style.Failure, "Export failed"); | ||||||||||||||||
showFailureToast(error, { title: "Export failed" }); | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
const secrets = parseSecrets(getSecrets(EXPORT_FILE_PATH)); | ||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. style: getSecrets and parseSecrets calls should be wrapped in try-catch as they could throw errors
Suggested change
|
||||||||||||||||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,31 +1,32 @@ | ||||||||||||||||
import { showToast, Toast } from "@raycast/api"; | ||||||||||||||||
import { EXPORT_FILE_PATH } from "./constants/ente"; | ||||||||||||||||
import { getPreferenceValues, showToast, Toast } from "@raycast/api"; | ||||||||||||||||
import { DEFAULT_EXPORT_DIR_PATH, EXPORT_FILE_PATH } from "./constants/ente"; | ||||||||||||||||
import { checkEnteBinary, createEntePath, deleteEnteExport, exportEnteAuthSecrets } from "./helpers/ente"; | ||||||||||||||||
import { getSecrets, parseSecrets, storeSecrets } from "./helpers/secrets"; | ||||||||||||||||
|
||||||||||||||||
export default async function Command() { | ||||||||||||||||
const toast = await showToast({ | ||||||||||||||||
style: Toast.Style.Animated, | ||||||||||||||||
title: "Importing secrets", | ||||||||||||||||
}); | ||||||||||||||||
const toast = await showToast({ style: Toast.Style.Animated, title: "Importing secrets" }); | ||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. style: Multiple toast notifications could cause race conditions. Consider using showFailureToast from @raycast/utils for error cases. |
||||||||||||||||
|
||||||||||||||||
if (!checkEnteBinary()) { | ||||||||||||||||
showToast(Toast.Style.Failure, "Ente binary not found"); | ||||||||||||||||
} | ||||||||||||||||
Comment on lines
+9
to
+11
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. logic: The function continues execution after showing the binary not found error. This should return early to prevent further operations.
Suggested change
|
||||||||||||||||
|
||||||||||||||||
try { | ||||||||||||||||
createEntePath(DEFAULT_EXPORT_DIR_PATH()); | ||||||||||||||||
exportEnteAuthSecrets(); | ||||||||||||||||
Comment on lines
+14
to
+15
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. logic: These operations could fail but their errors aren't being caught. They should be inside the try block or have their own error handling. |
||||||||||||||||
|
||||||||||||||||
const secrets = parseSecrets(getSecrets(EXPORT_FILE_PATH)); | ||||||||||||||||
await storeSecrets(secrets); | ||||||||||||||||
|
||||||||||||||||
if (secrets.length > 0) { | ||||||||||||||||
toast.style = Toast.Style.Success; | ||||||||||||||||
toast.title = " "; | ||||||||||||||||
toast.message = `${secrets.length} secrets imported!`; | ||||||||||||||||
} else { | ||||||||||||||||
toast.style = Toast.Style.Failure; | ||||||||||||||||
toast.title = "No secrets found"; | ||||||||||||||||
toast.message = "Please check your export path"; | ||||||||||||||||
} | ||||||||||||||||
toast.style = secrets.length > 0 ? Toast.Style.Success : Toast.Style.Failure; | ||||||||||||||||
toast.title = secrets.length > 0 ? `${secrets.length} secrets imported!` : "No secrets found"; | ||||||||||||||||
toast.message = secrets.length > 0 ? "" : "Please check your export path"; | ||||||||||||||||
} catch (error) { | ||||||||||||||||
toast.style = Toast.Style.Failure; | ||||||||||||||||
toast.title = "Error importing secrets"; | ||||||||||||||||
if (error instanceof Error) { | ||||||||||||||||
toast.message = error.message; | ||||||||||||||||
} | ||||||||||||||||
toast.message = error instanceof Error ? error.message : "Unknown error"; | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
if (getPreferenceValues().deleteExport == true) { | ||||||||||||||||
deleteEnteExport(); | ||||||||||||||||
} | ||||||||||||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
syntax: The title should use the {PR_MERGE_DATE} placeholder instead of a hardcoded date. Change to
## [Bug fix] - {PR_MERGE_DATE}