Skip to content

Commit

Permalink
auto split webhook token when user input hook url (#1262)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomsun28 authored Sep 25, 2023
1 parent a1cdaa4 commit c05dee6
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -274,23 +274,44 @@
'alert.notice.type.wework-key' | i18n
}}</nz-form-label>
<nz-form-control [nzSpan]="12" [nzErrorTip]="'validation.required' | i18n">
<input [(ngModel)]="receiver.wechatId" nz-input [required]="receiver.type === 4" name="wechatId" type="text" />
<input
[(ngModel)]="receiver.wechatId"
(ngModelChange)="onSplitTokenStr(4)"
nz-input
[required]="receiver.type === 4"
name="wechatId"
type="text"
/>
</nz-form-control>
</nz-form-item>
<nz-form-item *ngIf="receiver.type === 5">
<nz-form-label [nzSpan]="7" nzFor="accessToken" [nzRequired]="receiver.type === 5">{{
'alert.notice.type.access-token' | i18n
}}</nz-form-label>
<nz-form-control [nzSpan]="12" [nzErrorTip]="'validation.required' | i18n">
<input [(ngModel)]="receiver.accessToken" nz-input [required]="receiver.type === 5" name="accessToken" type="text" />
<input
[(ngModel)]="receiver.accessToken"
(ngModelChange)="onSplitTokenStr(5)"
nz-input
[required]="receiver.type === 5"
name="accessToken"
type="text"
/>
</nz-form-control>
</nz-form-item>
<nz-form-item *ngIf="receiver.type === 6">
<nz-form-label [nzSpan]="7" nzFor="wechatId" [nzRequired]="receiver.type === 6">{{
'alert.notice.type.fei-shu-key' | i18n
}}</nz-form-label>
<nz-form-control [nzSpan]="12" [nzErrorTip]="'validation.required' | i18n">
<input [(ngModel)]="receiver.wechatId" nz-input [required]="receiver.type === 6" name="wechatId" type="text" />
<input
[(ngModel)]="receiver.wechatId"
(ngModelChange)="onSplitTokenStr(6)"
nz-input
[required]="receiver.type === 6"
name="wechatId"
type="text"
/>
</nz-form-control>
</nz-form-item>
<nz-form-item *ngIf="receiver.type === 7">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,36 @@ export class AlertNoticeComponent implements OnInit {
isSendTestButtonLoading: boolean = false;
receiver!: NoticeReceiver;

onSplitTokenStr(type: number) {
let index = -1;
switch (this.receiver?.type) {
case 4:
if (this.receiver?.wechatId) {
index = this.receiver.wechatId.indexOf('key=');
if (index > 0) {
this.receiver.wechatId = this.receiver.wechatId.substring(index + 4);
}
}
break;
case 5:
if (this.receiver?.accessToken) {
index = this.receiver.accessToken.indexOf('access_token=');
if (index > 0) {
this.receiver.accessToken = this.receiver.accessToken.substring(index + 13);
}
}
break;
case 6:
if (this.receiver?.wechatId) {
index = this.receiver.wechatId.indexOf('hook');
if (index > 0) {
this.receiver.wechatId = this.receiver.wechatId.substring(index + 5);
}
}
break;
}
}

onNewNoticeReceiver() {
this.receiver = new NoticeReceiver();
this.isManageReceiverModalVisible = true;
Expand Down

0 comments on commit c05dee6

Please sign in to comment.