Skip to content

Commit

Permalink
fix(object-storage):preview & copyURL (#4444)
Browse files Browse the repository at this point in the history
  • Loading branch information
xudaotutou authored Dec 22, 2023
1 parent 6cb761e commit b9418ed
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 43 deletions.
39 changes: 0 additions & 39 deletions frontend/providers/objectstorage/README.md
Original file line number Diff line number Diff line change
@@ -1,40 +1 @@
This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app).

## Getting Started

First, run the development server:

```bash
npm run dev
# or
yarn dev
# or
pnpm dev
# or
bun dev
```

Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.

You can start editing the page by modifying `pages/index.tsx`. The page auto-updates as you edit the file.

[API routes](https://nextjs.org/docs/api-routes/introduction) can be accessed on [http://localhost:3000/api/hello](http://localhost:3000/api/hello). This endpoint can be edited in `pages/api/hello.ts`.

The `pages/api` directory is mapped to `/api/*`. Files in this directory are treated as [API routes](https://nextjs.org/docs/api-routes/introduction) instead of React pages.

This project uses [`next/font`](https://nextjs.org/docs/basic-features/font-optimization) to automatically optimize and load Inter, a custom Google Font.

## Learn More

To learn more about Next.js, take a look at the following resources:

- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.

You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your feedback and contributions are welcome!

## Deploy on Vercel

The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.

Check out our [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more details.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { deleteObject, listObjects } from '@/api/s3';
import { FolderPlaceholder, QueryKey } from '@/consts';
import { Authority, FolderPlaceholder, QueryKey } from '@/consts';
import { useOssStore } from '@/store/ossStore';
import {
AbsoluteCenter,
Expand Down Expand Up @@ -42,7 +42,7 @@ import VisibityIcon from '../Icons/VisibilityIcon';
import LinkIcon from '../Icons/LinkIcon';
import FileIcon from '../Icons/FileIcon';
import FolderIcon from '../Icons/FolderIcon';
import { GetObjectCommand, _Object } from '@aws-sdk/client-s3';
import { GetObjectCommand, S3, S3Client } from '@aws-sdk/client-s3';
import { useToast } from '@/hooks/useToast';
import { useEffect, useState } from 'react';
import ArrowDownSLineIcon from '../Icons/ArrowDownSLineIcon';
Expand Down Expand Up @@ -205,6 +205,23 @@ export default function FileManager({ ...styles }: FlexProps) {
isDir: true
});
const fuseList = fuse.search(searchVal);
// get url
const generateUrl = async (client: S3, Bucket: string, Key: string) => {
if (bucket?.policy === Authority.private) {
return getSignedUrl(
client,
new GetObjectCommand({
Bucket,
Key
})
);
} else {
const ep = await client.config.endpoint!();
const { protocol, hostname, path } = ep;
const url = `${protocol}//${hostname}${path}${Bucket}/${Key}`;
return url;
}
};
// --------
// budle delete
const deleteCheckBoxGroupState = useCheckboxGroup({
Expand Down Expand Up @@ -243,6 +260,7 @@ export default function FileManager({ ...styles }: FlexProps) {
});
deleteCheckBoxGroupState.setValue([]);
};

const trueFileList = fileList.filter(
(f) => !((f.fileName === '..' && f.isDir) || f.fileName === FolderPlaceholder)
);
Expand Down Expand Up @@ -409,7 +427,7 @@ export default function FileManager({ ...styles }: FlexProps) {
onClick={(e) => {
e.stopPropagation();
if (!s3client || !Bucket) return;
getSignedUrl(s3client, new GetObjectCommand({ Bucket, Key: file.Key }))
generateUrl(s3client, Bucket, file.Key)
.then((url) => {
window.open(new URL(url));
})
Expand All @@ -430,7 +448,7 @@ export default function FileManager({ ...styles }: FlexProps) {
onClick={(e) => {
e.stopPropagation();
if (!s3client || !Bucket) return;
getSignedUrl(s3client, new GetObjectCommand({ Bucket, Key: file.Key }))
generateUrl(s3client, Bucket, file.Key)
.then((url) => {
copyData(url);
})
Expand Down

0 comments on commit b9418ed

Please sign in to comment.