Skip to content

Commit

Permalink
improve get domains list and hide share directory when unavailable (#189
Browse files Browse the repository at this point in the history
)
  • Loading branch information
lihsai0 authored Jun 28, 2024
1 parent a746d12 commit cfa8db8
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 10 deletions.
5 changes: 3 additions & 2 deletions create-desktop-file.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ THIS_BASE_PATH=$(dirname "${THIS_PATH}")
cd "$THIS_BASE_PATH"
FULL_PATH=$(pwd)
cd "${WORKING_DIR}"
cat <<EOS > "kodo-browser.desktop"
DESKTOP_FILE_NAME="kodo-browser.desktop"
cat <<EOS > "${DESKTOP_FILE_NAME}"
[Desktop Entry]
Name=Kodo Browser
Comment=Kodo Browser for Linux
Expand All @@ -17,4 +18,4 @@ MimeType=x-scheme-handler/kodobrowser
Icon=${FULL_PATH}/resources/app/renderer/static/brand/qiniu.png
Categories=Utility;Development;
EOS
chmod +x "Kodo Browser.desktop"
chmod +x "${DESKTOP_FILE_NAME}"
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "kodo-browser",
"version": "2.3.0",
"version": "2.3.1",
"license": "Apache-2.0",
"author": {
"name": "Rong Zhou",
Expand Down Expand Up @@ -111,7 +111,7 @@
"form-data": "^4.0.0",
"js-base64": "^3.4.5",
"js-md5": "^0.7.3",
"kodo-s3-adapter-sdk": "0.6.0",
"kodo-s3-adapter-sdk": "0.6.1",
"lockfile": "^1.0.4",
"lodash": "^4.17.21",
"mime": "^2.3.1",
Expand Down
14 changes: 13 additions & 1 deletion src/renderer/modules/auth/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import lodash from "lodash";
import * as LocalLogger from "@renderer/modules/local-logger";
import * as QiniuClient from "@renderer/modules/qiniu-client";

import {AkItem, EndpointType, ShareSession} from "./types";
import {AkItem, AkSpecialType, EndpointType, ShareSession} from "./types";
import {authPersistence} from "./persistence";

let currentUser: AkItem | null = null;
Expand Down Expand Up @@ -32,6 +32,7 @@ export async function signIn(akItem: AkItem, remember: boolean) {
QiniuClient.clearAllCache();
throw err;
}
akItem.specialType = getAkSpecialType(akItem.accessKey);
currentUser = akItem;
if (remember) {
await authPersistence.save(akItem);
Expand Down Expand Up @@ -78,6 +79,7 @@ export async function signInWithShareLink({
endpointType: EndpointType.ShareSession,
accessKey: verifyShareResult.federated_ak,
accessSecret: verifyShareResult.federated_sk,
specialType: getAkSpecialType(verifyShareResult.federated_ak),
};
shareSession = {
sessionToken: verifyShareResult.session_token,
Expand Down Expand Up @@ -108,6 +110,7 @@ export async function signInWithShareSession({
currentUser = {
...akItem,
endpointType: EndpointType.ShareSession,
specialType: getAkSpecialType(akItem.accessKey),
};
shareSession = session;
// do not remember always;
Expand All @@ -124,6 +127,15 @@ export function getCurrentUser(): AkItem | null {
return currentUser;
}

export function getAkSpecialType(accessKey: string = ""): AkSpecialType | undefined {
if (accessKey.length === 44 && accessKey.startsWith("IAM-")) {
return AkSpecialType.IAM;
} else if (accessKey.startsWith("STS-")) {
return AkSpecialType.STS;
}
return;
}

export function getShareSession(): ShareSession | null {
return shareSession;
}
Expand Down
6 changes: 6 additions & 0 deletions src/renderer/modules/auth/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,16 @@ export enum EndpointType {
ShareSession = "shareSession",
}

export enum AkSpecialType {
IAM = "IAM",
STS = "STS",
}

export interface AkItem {
endpointType: EndpointType,
accessKey: string,
accessSecret: string,
specialType?: AkSpecialType,
description?: string,
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@ const FileOperations: React.FC<RowCellDataProps & FileOperationsCellCallbackProp
const canRestore = isFile && ["Archive", "DeepArchive"].includes(file.storageClass);

const shouldShowShareDirButton = useMemo(() => {
if (isFile || !currentUser) {
if (
isFile ||
!currentUser ||
currentUser.specialType ||
bucketGrantedPermission
) {
return false;
}

Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7364,10 +7364,10 @@ klona@^2.0.4, klona@^2.0.5:
resolved "https://registry.yarnpkg.com/klona/-/klona-2.0.5.tgz#d166574d90076395d9963aa7a928fabb8d76afbc"
integrity sha512-pJiBpiXMbt7dkzXe8Ghj/u4FfXOOa98fPW+bihOJ4SjnoijweJrNThJfd3ifXpXhREjpoF2mZVH1GfS9LV3kHQ==

kodo-s3-adapter-sdk@0.6.0:
version "0.6.0"
resolved "https://registry.yarnpkg.com/kodo-s3-adapter-sdk/-/kodo-s3-adapter-sdk-0.6.0.tgz#d1e5f2687683748ec3bf33602d6ad9b1bc2f396b"
integrity sha512-aq4LBU7GCErC3YZCmIcMhLgfjlYzMwF5WJ80qUT/UqAsk0/mhgrG3oj2yGmVooid6UhBuTe3to7XjddyUkdj3A==
kodo-s3-adapter-sdk@0.6.1:
version "0.6.1"
resolved "https://registry.yarnpkg.com/kodo-s3-adapter-sdk/-/kodo-s3-adapter-sdk-0.6.1.tgz#319da35d9c3a8f5e1e3987b9a89835ac1b43953f"
integrity sha512-RWxb1I0EjPdZZC3Q7FBHBKjc3ctzm/Hy2hw3yk6mKRs+rIPyzbjuTyG1j9RrhewY8ZeG3Avlozrlg6YG36ySqg==
dependencies:
agentkeepalive "^4.2.1"
async-lock "^1.2.4"
Expand Down

0 comments on commit cfa8db8

Please sign in to comment.