Skip to content

Commit

Permalink
dte
Browse files Browse the repository at this point in the history
  • Loading branch information
solita-nhuttu committed Feb 8, 2024
1 parent 1c5a134 commit 4f12933
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 46 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main_3tee.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
push: true
tags: nhuttu.azurecr.io/${{ secrets.ACR_USERNAME }}/webimage:${{ github.sha }}
file: ./Dockerfile
secrets: |
secret-envs: |
NEXT_PUBLIC_TESTATAAN=${{ secrets.NEXT_PUBLIC_TESTATAAN }}
AZURE_CONNECTION_STRING=${{secrets.AZURE_CONNECTION_STRING}}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev",
"dev": "next dev -p 3003",
"build": "next build",
"start": "next start",
"lint": "next lint"
Expand Down
78 changes: 35 additions & 43 deletions src/app/api/file/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,67 +9,59 @@ const AZURE_STORAGE_CONNECTION_STRING =
console.log(AZURE_STORAGE_CONNECTION_STRING, "heiii");

export async function POST(req: NextRequest, res: NextResponse) {
try {
const data = await req.formData();
const data = await req.formData();

const file: File | null = data.get("file") as unknown as File;
const file: File | null = data.get("file") as unknown as File;

console.log(file);
console.log(file);

const blobServiceClient = BlobServiceClient.fromConnectionString(
AZURE_STORAGE_CONNECTION_STRING,
);
const blobServiceClient = BlobServiceClient.fromConnectionString(
AZURE_STORAGE_CONNECTION_STRING,
);

const containerName = "$web";
const containerName = "$web";

const containerClient = blobServiceClient.getContainerClient(containerName);
const containerClient = blobServiceClient.getContainerClient(containerName);

const blobName = file.name;
const blobName = file.name;

const blockBlobClient = containerClient.getBlockBlobClient(blobName);
const blockBlobClient = containerClient.getBlockBlobClient(blobName);

const options: BlockBlobUploadOptions = {
blobHTTPHeaders: { blobContentType: file.type },
};
const options: BlockBlobUploadOptions = {
blobHTTPHeaders: { blobContentType: file.type },
};

if (!file) {
return NextResponse.error();
}
const bytes = await file.arrayBuffer();
const buffer = Buffer.from(bytes);
if (!file) {
return NextResponse.error();
}
const bytes = await file.arrayBuffer();
const buffer = Buffer.from(bytes);

const uploadBlobResponse = await blockBlobClient.upload(
buffer,
buffer.length,
options,
);
const uploadBlobResponse = await blockBlobClient.upload(
buffer,
buffer.length,
options,
);

return NextResponse.json(uploadBlobResponse);
} catch (error) {
return NextResponse.json(error);
}
return NextResponse.json(uploadBlobResponse);
}

export async function GET(req: NextRequest, res: NextResponse) {
try {
const blobServiceClient = BlobServiceClient.fromConnectionString(
AZURE_STORAGE_CONNECTION_STRING,
);
const blobServiceClient = BlobServiceClient.fromConnectionString(
AZURE_STORAGE_CONNECTION_STRING,
);

const containerName = "$web";
const containerName = "$web";

const containerClient = blobServiceClient.getContainerClient(containerName);
const containerClient = blobServiceClient.getContainerClient(containerName);

const q = [];
const q = [];

for await (const blob of containerClient.listBlobsFlat()) {
const blockBlobClient = containerClient.getBlockBlobClient(blob.name);
for await (const blob of containerClient.listBlobsFlat()) {
const blockBlobClient = containerClient.getBlockBlobClient(blob.name);

q.push(blockBlobClient.url);
}

return NextResponse.json(q);
} catch (error) {
return NextResponse.json(error);
q.push(blockBlobClient.url);
}

return NextResponse.json(q);
}
3 changes: 2 additions & 1 deletion src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export default function Page() {
"use server";
console.log(formData);
}

const d = new Date();
return (
<div>
<form action={create}>
Expand All @@ -12,6 +12,7 @@ export default function Page() {
Submit
</button>
<div>
<p>{d.toISOString()}</p>
klo 10.15.
{process.env.NEXT_PUBLIC_TESTATAAN ?? "Ei olla azuressa"}
</div>
Expand Down

0 comments on commit 4f12933

Please sign in to comment.