adjust bulk creation
This commit is contained in:
@@ -48,6 +48,24 @@ func (s *ClientService) Save(tx *gorm.DB, act string, data json.RawMessage, host
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
case "addbulk":
|
||||
var clients []*model.Client
|
||||
err = json.Unmarshal(data, &clients)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = json.Unmarshal(clients[0].Inbounds, &inboundIds)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = s.updateLinksWithFixedInbounds(tx, clients, inboundIds, hostname)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = tx.Save(clients).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
case "del":
|
||||
var id uint
|
||||
err = json.Unmarshal(data, &id)
|
||||
|
||||
@@ -74,6 +74,7 @@
|
||||
v-model="clientInbounds"
|
||||
:items="inboundTags"
|
||||
:label="$t('client.inboundTags')"
|
||||
:return-object="false"
|
||||
multiple
|
||||
chips
|
||||
hide-details
|
||||
@@ -236,7 +237,7 @@ export default {
|
||||
computed: {
|
||||
clientInbounds: {
|
||||
get() { return this.client.inbounds.length>0 ? this.client.inbounds : [] },
|
||||
set(v:any[]) { this.client.inbounds = v.length == 0 ? [] : v.map(i => i.value) }
|
||||
set(v:number[]) { this.client.inbounds = v.length == 0 ? [] : v }
|
||||
},
|
||||
expDate: {
|
||||
get() { return this.client.expiry},
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<v-dialog transition="dialog-bottom-transition" width="800">
|
||||
<v-card class="rounded-lg">
|
||||
<v-card-title>
|
||||
{{ $t('bulk.add') }}
|
||||
{{ $t('actions.addbulk') }}
|
||||
</v-card-title>
|
||||
<v-divider></v-divider>
|
||||
<v-card-text style="padding: 0 16px; overflow-y: scroll;">
|
||||
@@ -53,6 +53,7 @@
|
||||
v-model="bulkData.clientInbounds"
|
||||
:items="inboundTags"
|
||||
:label="$t('client.inboundTags')"
|
||||
:return-object="false"
|
||||
multiple
|
||||
chips
|
||||
hide-details
|
||||
@@ -60,6 +61,7 @@
|
||||
</v-col>
|
||||
</v-row>
|
||||
</v-container>
|
||||
<pre dir="ltr">{{ bulkData }}</pre>
|
||||
</v-card-text>
|
||||
<v-card-actions>
|
||||
<v-spacer></v-spacer>
|
||||
@@ -133,6 +135,7 @@ export default {
|
||||
push.error(i18n.global.t('error.dplData'))
|
||||
return
|
||||
}
|
||||
this.clients = []
|
||||
this.loading = true
|
||||
for(let i=0;i<this.count;i++){
|
||||
const name = this.genByPattern(this.bulkData.name, i)
|
||||
@@ -150,8 +153,7 @@ export default {
|
||||
group: this.bulkData.group
|
||||
}))
|
||||
}
|
||||
this.$emit('save', this.clients, this.bulkData.clientInbounds)
|
||||
this.resetData() // reset to default
|
||||
this.$emit('save', this.clients)
|
||||
this.loading = false
|
||||
},
|
||||
genByPattern(pattern: any[], order :number){
|
||||
|
||||
@@ -96,6 +96,7 @@ export default {
|
||||
actions: {
|
||||
action: "Action",
|
||||
add: "Add",
|
||||
addbulk: "Add Bulk",
|
||||
new: "New",
|
||||
edit: "Edit",
|
||||
del: "Delete",
|
||||
@@ -173,7 +174,6 @@ export default {
|
||||
sub: "External Subscription",
|
||||
},
|
||||
bulk: {
|
||||
add: "Add Bulk",
|
||||
order: "Order",
|
||||
random: "Random",
|
||||
},
|
||||
|
||||
@@ -95,6 +95,7 @@ export default {
|
||||
actions: {
|
||||
action: "فرمان",
|
||||
add: "ایجاد",
|
||||
addbulk: "ایجاد انبوه",
|
||||
new: "جدید",
|
||||
edit: "ویرایش",
|
||||
del: "حذف",
|
||||
@@ -172,7 +173,6 @@ export default {
|
||||
sub: "سابسکریپشن خارجی",
|
||||
},
|
||||
bulk: {
|
||||
add: "ایجاد انبوه",
|
||||
order: "ترتیب",
|
||||
random: "تصادفی",
|
||||
},
|
||||
|
||||
@@ -96,6 +96,7 @@ export default {
|
||||
actions: {
|
||||
action: "Действие",
|
||||
add: "Добавить",
|
||||
addbulk: "Добавить пакетно",
|
||||
new: "Новый",
|
||||
edit: "Редактировать",
|
||||
del: "Удалить",
|
||||
@@ -173,7 +174,6 @@ export default {
|
||||
sub: "Внешняя подписка",
|
||||
},
|
||||
bulk: {
|
||||
add: "Добавить пакетно",
|
||||
order: "Порядок",
|
||||
random: "Случайный",
|
||||
},
|
||||
|
||||
@@ -94,6 +94,7 @@ export default {
|
||||
actions: {
|
||||
action: "Hành động",
|
||||
add: "Thêm",
|
||||
addbulk: "Thêm Hàng loạt",
|
||||
new: "Mới",
|
||||
edit: "Chỉnh sửa",
|
||||
del: "Xóa",
|
||||
@@ -171,7 +172,6 @@ export default {
|
||||
sub: "Đăng ký bên ngoài",
|
||||
},
|
||||
bulk: {
|
||||
add: "Thêm Hàng loạt",
|
||||
order: "Sắp xếp",
|
||||
random: "Ngẫu nhiên",
|
||||
},
|
||||
|
||||
@@ -94,6 +94,7 @@ export default {
|
||||
actions: {
|
||||
action: "操作",
|
||||
add: "添加",
|
||||
addbulk: "批量添加",
|
||||
new: "新建",
|
||||
edit: "编辑",
|
||||
del: "删除",
|
||||
@@ -171,7 +172,6 @@ export default {
|
||||
sub: "外部订阅",
|
||||
},
|
||||
bulk: {
|
||||
add: "批量添加",
|
||||
order: "排序",
|
||||
random: "随机",
|
||||
},
|
||||
|
||||
@@ -95,6 +95,7 @@ export default {
|
||||
actions: {
|
||||
action: "操作",
|
||||
add: "添加",
|
||||
addbulk: "批量添加",
|
||||
new: "新建",
|
||||
edit: "編輯",
|
||||
del: "刪除",
|
||||
@@ -172,7 +173,6 @@ export default {
|
||||
sub: "外部訂閱",
|
||||
},
|
||||
bulk: {
|
||||
add: "批量添加",
|
||||
order: "排序",
|
||||
random: "隨機",
|
||||
},
|
||||
|
||||
@@ -47,7 +47,7 @@
|
||||
<template v-slot:prepend>
|
||||
<v-icon icon="mdi-account-multiple-plus"></v-icon>
|
||||
</template>
|
||||
<v-list-item-title v-text="$t('bulk.add')"></v-list-item-title>
|
||||
<v-list-item-title v-text="$t('actions.addbulk')"></v-list-item-title>
|
||||
</v-list-item>
|
||||
</v-list>
|
||||
</v-menu>
|
||||
@@ -535,8 +535,20 @@ const closeBulk = () => {
|
||||
addBulkModal.value = false
|
||||
}
|
||||
|
||||
const saveBulk = async (bulkClients: Client[], clientInbounds: number[]) => {
|
||||
clients.value.push(...bulkClients)
|
||||
closeBulk()
|
||||
const saveBulk = async (bulkClients: Client[]) => {
|
||||
// Check duplicate name
|
||||
const oldNames = new Set(clients.value.map(c => c.name))
|
||||
const newNames = new Set(bulkClients.map(c => c.name))
|
||||
const allNames = new Set([...clients.value.map(c => c.name), ...bulkClients.map(c => c.name)])
|
||||
if (newNames.size != bulkClients.length || oldNames.size + newNames.size != allNames.size) {
|
||||
push.error({
|
||||
message: i18n.global.t('error.dplData') + ": " + i18n.global.t('client.name')
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// save data
|
||||
const success = await Data().save("clients", "addbulk", bulkClients)
|
||||
if (success) closeBulk()
|
||||
}
|
||||
</script>
|
||||
Reference in New Issue
Block a user