Skip to content

Commit 9ee3832

Browse files
feat(website): Optimize website expiration time setting (#8061)
1 parent f71ff7d commit 9ee3832

6 files changed

Lines changed: 30 additions & 8 deletions

File tree

agent/app/service/runtime.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,7 @@ func (r *RuntimeService) Update(req request.RuntimeUpdate) error {
518518
runtime.CodeDir = req.CodeDir
519519
runtime.Port = strings.Join(hostPorts, ",")
520520
runtime.Status = constant.StatusReCreating
521+
runtime.ContainerName = req.Params["CONTAINER_NAME"].(string)
521522
_ = runtimeRepo.Save(runtime)
522523
go reCreateRuntime(runtime)
523524
}

agent/app/service/website.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ func (w WebsiteService) CreateWebsite(create request.WebsiteCreate) (err error)
259259
primaryDomain = fmt.Sprintf("%s:%v", domains[0].Domain, domains[0].Port)
260260
}
261261

262-
defaultDate, _ := time.Parse(constant.DateLayout, constant.DefaultDate)
262+
defaultDate, _ := time.Parse(constant.DateLayout, constant.WebsiteDefaultExpireDate)
263263
website := &model.Website{
264264
PrimaryDomain: primaryDomain,
265265
Type: create.Type,

agent/constant/common.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,11 @@ const (
2323
TimeOut20s = 20
2424
TimeOut5m = 300
2525

26-
DateLayout = "2006-01-02" // or use time.DateOnly while go version >= 1.20
27-
DefaultDate = "1970-01-01"
28-
DateTimeLayout = "2006-01-02 15:04:05" // or use time.DateTime while go version >= 1.20
29-
DateTimeSlimLayout = "20060102150405"
26+
DateLayout = "2006-01-02" // or use time.DateOnly while go version >= 1.20
27+
DefaultDate = "1970-01-01"
28+
DateTimeLayout = "2006-01-02 15:04:05" // or use time.DateTime while go version >= 1.20
29+
DateTimeSlimLayout = "20060102150405"
30+
WebsiteDefaultExpireDate = "9999-12-31"
3031
)
3132

3233
const (

agent/init/migration/migrate.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ func InitAgentDB() {
2727
migrations.AddOllamaModel,
2828
migrations.UpdateSettingStatus,
2929
migrations.InitDefault,
30+
migrations.UpdateWebsiteExpireDate,
3031
})
3132
if err := m.Migrate(); err != nil {
3233
global.LOG.Error(err)

agent/init/migration/migrations/init.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package migrations
33
import (
44
"fmt"
55
"path"
6+
"time"
67

78
"github.com/1Panel-dev/1Panel/agent/app/dto/request"
89
"github.com/1Panel-dev/1Panel/agent/app/model"
@@ -296,3 +297,17 @@ var InitDefault = &gormigrate.Migration{
296297
return nil
297298
},
298299
}
300+
301+
var UpdateWebsiteExpireDate = &gormigrate.Migration{
302+
ID: "20250304-update-website",
303+
Migrate: func(tx *gorm.DB) error {
304+
targetDate := time.Date(9999, 12, 31, 0, 0, 0, 0, time.UTC)
305+
306+
if err := tx.Model(&model.Website{}).
307+
Where("expire_date = ?", time.Date(1970, 1, 1, 0, 0, 0, 0, time.UTC)).
308+
Update("expire_date", targetDate).Error; err != nil {
309+
return err
310+
}
311+
return nil
312+
},
313+
}

frontend/src/views/website/website/index.vue

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ const shortcuts = [
272272
{
273273
text: useI18n().t('website.ever'),
274274
value: () => {
275-
return new Date('1970-01-01');
275+
return new Date('9999-12-31');
276276
},
277277
},
278278
{
@@ -379,7 +379,7 @@ const openConfig = (id: number) => {
379379
380380
const isEver = (time: string) => {
381381
const expireDate = new Date(time);
382-
return expireDate < new Date('1970-01-02');
382+
return expireDate > new Date('9999-12-30');
383383
};
384384
385385
const isBeforeNow = (time: string) => {
@@ -415,10 +415,14 @@ const setdateRefs = (ref: any) => {
415415
};
416416
417417
const initDatePicker = (row: any) => {
418-
if (dataRef.value == undefined && row.oldExpireDate == undefined && isBeforeNow(row.expireDate)) {
418+
if (
419+
(dataRef.value == undefined && row.oldExpireDate == undefined && isBeforeNow(row.expireDate)) ||
420+
isEver(row.expireDate)
421+
) {
419422
row.oldExpireDate = row.expireDate;
420423
const date = new Date().toLocaleDateString();
421424
row.expireDate = date;
425+
return;
422426
}
423427
};
424428

0 commit comments

Comments
 (0)