#107: Fixed double apps and general duplicates
This commit is contained in:
+24
-11
@@ -4221,9 +4221,10 @@ func loadSpecificApps(resp http.ResponseWriter, request *http.Request) {
|
||||
|
||||
// Field1 & 2 can be a lot of things..
|
||||
type tmpStruct struct {
|
||||
URL string `json:"url"`
|
||||
Field1 string `json:"field_1"`
|
||||
Field2 string `json:"field_2"`
|
||||
URL string `json:"url"`
|
||||
Field1 string `json:"field_1"`
|
||||
Field2 string `json:"field_2"`
|
||||
ForceUpdate bool `json:"force_update"`
|
||||
}
|
||||
//log.Printf("Body: %s", string(body))
|
||||
|
||||
@@ -4265,7 +4266,13 @@ func loadSpecificApps(resp http.ResponseWriter, request *http.Request) {
|
||||
log.Printf("FAiled reading folder: %s", err)
|
||||
}
|
||||
_ = r
|
||||
iterateAppGithubFolders(fs, dir, "", "", true)
|
||||
|
||||
if tmpBody.ForceUpdate {
|
||||
log.Printf("Running with force update!")
|
||||
} else {
|
||||
log.Printf("Updating apps with updates")
|
||||
}
|
||||
iterateAppGithubFolders(fs, dir, "", "", tmpBody.ForceUpdate)
|
||||
|
||||
} else if strings.Contains(tmpBody.URL, "s3") {
|
||||
//https://docs.aws.amazon.com/sdk-for-go/api/service/s3/
|
||||
@@ -4492,6 +4499,11 @@ func iterateWorkflowGithubFolders(fs billy.Filesystem, dir []os.FileInfo, extra
|
||||
// Onlyname is used to
|
||||
func iterateAppGithubFolders(fs billy.Filesystem, dir []os.FileInfo, extra string, onlyname string, forceUpdate bool) error {
|
||||
var err error
|
||||
|
||||
allapps := []WorkflowApp{}
|
||||
|
||||
// It's here to prevent getting them in every iteration
|
||||
ctx := context.Background()
|
||||
for _, file := range dir {
|
||||
if len(onlyname) > 0 && file.Name() != onlyname {
|
||||
continue
|
||||
@@ -4591,12 +4603,12 @@ func iterateAppGithubFolders(fs billy.Filesystem, dir []os.FileInfo, extra strin
|
||||
fmt.Sprintf("%s:%s_%s", baseDockerName, newName, workflowapp.AppVersion),
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
allapps, err := getAllWorkflowApps(ctx)
|
||||
if err != nil {
|
||||
log.Printf("Failed getting apps to verify: %s", err)
|
||||
continue
|
||||
//return err
|
||||
if len(allapps) == 0 {
|
||||
allapps, err = getAllWorkflowApps(ctx)
|
||||
if err != nil {
|
||||
log.Printf("Failed getting apps to verify: %s", err)
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
// Make an option to override existing apps?
|
||||
@@ -4607,7 +4619,7 @@ func iterateAppGithubFolders(fs billy.Filesystem, dir []os.FileInfo, extra strin
|
||||
if app.Name == workflowapp.Name && app.AppVersion == workflowapp.AppVersion {
|
||||
// FIXME: Check if there's a new APP_SDK as well.
|
||||
// Skip this check if app_sdk is new.
|
||||
if app.Hash == md5 && app.Hash != "" {
|
||||
if app.Hash == md5 && app.Hash != "" && !forceUpdate {
|
||||
skip = true
|
||||
break
|
||||
}
|
||||
@@ -4677,6 +4689,7 @@ func iterateAppGithubFolders(fs billy.Filesystem, dir []os.FileInfo, extra strin
|
||||
|
||||
if len(removeApps) > 0 {
|
||||
for _, item := range removeApps {
|
||||
log.Printf("Removing duplicate: %s", item)
|
||||
err = DeleteKey(ctx, "workflowapp", item)
|
||||
if err != nil {
|
||||
log.Printf("Failed deleting %s", item)
|
||||
|
||||
+12
-5
@@ -743,7 +743,7 @@ const Apps = (props) => {
|
||||
null
|
||||
|
||||
// Load data e.g. from github
|
||||
const getSpecificApps = (url) => {
|
||||
const getSpecificApps = (url, forceUpdate) => {
|
||||
setValidation(true)
|
||||
|
||||
setIsLoading(true)
|
||||
@@ -761,6 +761,8 @@ const Apps = (props) => {
|
||||
parsedData["field_2"] = field2
|
||||
}
|
||||
|
||||
parsedData["force_update"] = forceUpdate
|
||||
|
||||
alert.success("Getting specific apps from your URL.")
|
||||
var cors = "cors"
|
||||
fetch(globalUrl+"/api/v1/apps/get_existing", {
|
||||
@@ -977,8 +979,8 @@ const Apps = (props) => {
|
||||
window.location.href = "/apps/new?id="+appValidation
|
||||
}
|
||||
|
||||
const handleGithubValidation = () => {
|
||||
getSpecificApps(openApi)
|
||||
const handleGithubValidation = (forceUpdate) => {
|
||||
getSpecificApps(openApi, forceUpdate)
|
||||
setLoadAppsModalOpen(false)
|
||||
}
|
||||
|
||||
@@ -1034,7 +1036,7 @@ const Apps = (props) => {
|
||||
>
|
||||
<DialogTitle>
|
||||
<div style={{color: "rgba(255,255,255,0.9)"}}>
|
||||
Load from github repo
|
||||
Load from github repo
|
||||
</div>
|
||||
</DialogTitle>
|
||||
<DialogContent style={{color: "rgba(255,255,255,0.65)"}}>
|
||||
@@ -1098,7 +1100,12 @@ const Apps = (props) => {
|
||||
Cancel
|
||||
</Button>
|
||||
<Button style={{borderRadius: "0px"}} disabled={openApi.length === 0 || !openApi.includes("http")} onClick={() => {
|
||||
handleGithubValidation()
|
||||
handleGithubValidation(true)
|
||||
}} color="primary">
|
||||
Force update
|
||||
</Button>
|
||||
<Button variant="outlined" style={{float: "left", borderRadius: "0px"}} disabled={openApi.length === 0 || !openApi.includes("http")} onClick={() => {
|
||||
handleGithubValidation(false)
|
||||
}} color="primary">
|
||||
Submit
|
||||
</Button>
|
||||
|
||||
Reference in New Issue
Block a user