Răsfoiți Sursa

feat: setACL public & private

ryanemax 1 lună în urmă
părinte
comite
996d01348c

+ 13 - 1
projects/textbook/src/app/comp-upload/example-upload/example-upload.component.html

@@ -18,4 +18,16 @@
     title="上传PDF"
   ></app-comp-upload>
 
-  <button (click)="download('http://hep-textbook.oss-cn-beijing.aliyuncs.com/undefined/2024-10-8/1728352740465-test.pdf','测试私有.pdf')">测试临时下载链接</button>
+
+<h1>测试私有下载</h1>
+
+<input type="text" [(ngModel)]="downloadUrl">
+<button (click)="download(downloadUrl,'测试私有.pdf')">测试临时下载链接</button>
+
+<h1>测试设置公开</h1>
+<input type="text" [(ngModel)]="publicUrl">
+<button (click)="public()">公开</button>
+
+<h1>测试设置私有</h1>
+<input type="text" [(ngModel)]="privateUrl">
+<button (click)="private()">私有</button>

+ 16 - 2
projects/textbook/src/app/comp-upload/example-upload/example-upload.component.ts

@@ -1,4 +1,5 @@
 import { Component, OnInit } from '@angular/core';
+import { FormsModule, ReactiveFormsModule } from '@angular/forms';
 import { CompUploadComponent } from '../comp-upload.component';
 import { ProvierOssAli } from '../provider-oss-aliyun';
 
@@ -7,11 +8,11 @@ import { ProvierOssAli } from '../provider-oss-aliyun';
   templateUrl: './example-upload.component.html',
   styleUrls: ['./example-upload.component.scss'],
   standalone: true,
-  imports:[CompUploadComponent]
+  imports:[CompUploadComponent,FormsModule,ReactiveFormsModule]
 })
 export class ExampleUploadComponent  implements OnInit {
 
-  ossProvider: { upload: any, signatureUrl: any, download:any } | undefined;
+  ossProvider: any|{ upload: any, signatureUrl: any, download:any } | undefined;
   constructor() { 
     this.ossProvider = new ProvierOssAli();
   }
@@ -21,7 +22,20 @@ export class ExampleUploadComponent  implements OnInit {
   upload(ev:any){
     console.log(ev)
   }
+
+  downloadUrl:string = "http://hep-textbook.oss-cn-beijing.aliyuncs.com/undefined/2024-10-8/1728352740465-test.pdf"
   download(url:string,fileName?:string){
     let tempUrl = this.ossProvider?.download(url,fileName);
   }
+  publicUrl:string|undefined = "http://hep-textbook.oss-cn-beijing.aliyuncs.com/undefined/2024-10-8/1728352740465-test.pdf"
+  async public(){
+    console.log(await this.ossProvider?.setACLPublic(this.publicUrl))
+
+  }
+
+  privateUrl:string|undefined = "http://hep-textbook.oss-cn-beijing.aliyuncs.com/undefined/2024-10-8/1728352740465-test.pdf"
+  async private(){
+    console.log(await this.ossProvider?.setACLPrivate(this.privateUrl))
+
+  }
 }

+ 13 - 1
projects/textbook/src/app/comp-upload/provider-oss-aliyun.ts

@@ -101,7 +101,19 @@ export class ProvierOssAli{
         });
         console.log(r1)
         return r1;
-
+    }
+    // 设置已上传URL为私有文件
+    async setACLPrivate(url:string){
+        await this.initClient();
+        let urlObj = new URL(url);
+        let r1 = await this.client?.putACL(urlObj.pathname,"private")
+        return r1
+    }
+    async setACLPublic(url:string){
+        await this.initClient();
+        let urlObj = new URL(url);
+        let r1 = await this.client?.putACL(urlObj.pathname,"public-read-write")
+        return r1
     }
 
 }