Skip to content

Commit

Permalink
feat: Add GUI to add custom sites under Options->Advanced (xbapps#1246)
Browse files Browse the repository at this point in the history
* Create Custom Site GUI

* fix typy

* fix typo

---------

Co-authored-by: crwxaj <52156245+crwxaj@users.noreply.github.com>
  • Loading branch information
toshski and crwxaj authored Apr 30, 2023
1 parent d0e1cb6 commit 72c6834
Show file tree
Hide file tree
Showing 3 changed files with 163 additions and 2 deletions.
88 changes: 88 additions & 0 deletions pkg/api/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ import (
"crypto/sha1"
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"os"
"path/filepath"
"regexp"
"strconv"
"strings"
"time"

restfulspec "github.com/emicklei/go-restful-openapi/v2"
Expand Down Expand Up @@ -134,6 +137,13 @@ type RequestCuepointsResponse struct {
Positions []string `json:"positions"`
Actions []string `json:"actions"`
}
type RequestSCustomSiteCreate struct {
Url string `json:"scraperUrl"`
Name string `json:"scraperName"`
Avatar string `json:"scraperAvatar"`
Company string `json:"scraperCompany"`
}

type ConfigResource struct{}

func (i ConfigResource) WebService() *restful.WebService {
Expand Down Expand Up @@ -216,6 +226,11 @@ func (i ConfigResource) WebService() *restful.WebService {
// "Cuepoints section endpoints"
ws.Route(ws.GET("/cuepoints").To(i.getDefaultCuepoints).
Metadata(restfulspec.KeyOpenAPITags, tags))

// "Cuepoints section endpoints"
ws.Route(ws.PUT("/custom-sites/create").To(i.createCustomSite).
Metadata(restfulspec.KeyOpenAPITags, tags))

return ws
}

Expand Down Expand Up @@ -754,3 +769,76 @@ func (i ConfigResource) getDefaultCuepoints(req *restful.Request, resp *restful.
json.Unmarshal([]byte(kv.Value), &cp)
resp.WriteHeaderAndEntity(http.StatusOK, &cp)
}
func (i ConfigResource) createCustomSite(req *restful.Request, resp *restful.Response) {
db, _ := models.GetDB()
defer db.Close()

var r RequestSCustomSiteCreate
err := req.ReadEntity(&r)
if err != nil {
log.Error(err)
return
}
if r.Url == "" || r.Name == "" {
return
}
r.Url = strings.TrimSpace(r.Url)
r.Name = strings.TrimSpace(r.Name)
r.Company = strings.TrimSpace(r.Company)
r.Avatar = strings.TrimSpace(r.Avatar)
if r.Company == "" {
r.Company = r.Name
}

var scraperConfig config.ScraperList
scraperConfig.Load()

re := regexp.MustCompile(`^(https?://)?(www\.)?([^./]+)\.`)
match := re.FindStringSubmatch(r.Url)
if len(match) < 3 {
return
}

r.Url = strings.TrimSuffix(r.Url, "/")

scrapers := make(map[string][]config.ScraperConfig)
scrapers["povr"] = scraperConfig.CustomScrapers.PovrScrapers
scrapers["slr"] = scraperConfig.CustomScrapers.SlrScrapers
scrapers["vrphub"] = scraperConfig.CustomScrapers.VrphubScrapers
scrapers["vrporn"] = scraperConfig.CustomScrapers.VrpornScrapers

exists := false
for key, group := range scrapers {
for idx, site := range group {
if site.URL == r.Url {
exists = true
scrapers[key][idx].Name = r.Name
scrapers[key][idx].Company = r.Company
scrapers[key][idx].AvatarUrl = r.Avatar
}
}
}

if !exists {
scraper := config.ScraperConfig{URL: r.Url, Name: r.Name, Company: r.Company, AvatarUrl: r.Avatar}
switch match[3] {
case "povr":
scrapers["povr"] = append(scrapers["povrr"], scraper)
case "sexlikereal":
scrapers["slr"] = append(scrapers["slr"], scraper)
case "vrphub":
scrapers["vrphub"] = append(scrapers["vrphub"], scraper)
case "vrporn":
scrapers["vrporn"] = append(scrapers["vrporn"], scraper)
}
}
scraperConfig.CustomScrapers.PovrScrapers = scrapers["povr"]
scraperConfig.CustomScrapers.SlrScrapers = scrapers["slr"]
scraperConfig.CustomScrapers.VrphubScrapers = scrapers["vrphub"]
scraperConfig.CustomScrapers.VrpornScrapers = scrapers["vrporn"]
fName := filepath.Join(common.AppDir, "scrapers.json")
list, _ := json.MarshalIndent(scraperConfig, "", " ")
ioutil.WriteFile(fName, list, 0644)

resp.WriteHeader(http.StatusOK)
}
9 changes: 9 additions & 0 deletions ui/src/locales/en-GB.json
Original file line number Diff line number Diff line change
Expand Up @@ -125,5 +125,14 @@
"Search Fields": "Search Fields",
"Defaults date range to the last week. Note:must match yyyy-mm-dd, include leading zeros": "Defaults date range to the last week. Note:must match yyyy-mm-dd, include leading zeros",
"Scraper does not exist": "Scraper does not exist",
"Restart XBR to load new Sties": "Restart XBR to load new Sties",
"Scraper Url": "Scraper Url",
"Name": "Name",
"Company": "Company",
"Avatar Url": "Avatar Url",
"Enter the Url to Studio Scene List": "Enter the Url to Studio Scene List",
"Enter Studio Name": "Enter Studio Name",
"Optional: defaults to Name": "Optional: defaults to Name",
"Optional": "Optional",
"Go": "Go"
}
68 changes: 66 additions & 2 deletions ui/src/views/options/sections/InterfaceAdvanced.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@
<div class="content">
<h3>{{ $t('Advanced') }}</h3>
<hr />
<div class="columns">
<b-tabs v-model="activeTab" size="medium" type="is-boxed" style="margin-left: 0px" id="importexporttab">
<b-tab-item label="Scene Details"/>
<b-tab-item label="Create Custom Site"/>
</b-tabs>

<!-- Screen Details Tab -->
<div class="columns" v-if="activeTab == 0">
<div class="column">
<section>
<b-field>
Expand All @@ -24,20 +30,78 @@
</section>
</div>
</div>

<!-- Custom Sites Tab -->
<div class="columns" v-if="activeTab == 1">
<div class="column">
<section>
<b-field :label="$t('Scraper Url')" label-position="on-border">
<b-input v-model="scraperUrl" :placeholder="$t('Enter the Url to Studio Scene List')" @input="validateScraperFields()"></b-input>
</b-field>
<b-field :label="$t('Name')" label-position="on-border">
<b-input v-model="scraperName" :placeholder="$t('Enter Studio Name')" @input="validateScraperFields()"></b-input>
</b-field>
<b-field :label="$t('Company')" label-position="on-border">
<b-input v-model="scraperCompany" :placeholder="$t('Optional: defaults to Name')"></b-input>
</b-field>
<b-field :label="$t('Avatar Url')" label-position="on-border">
<b-input v-model="scraperAvatar" :placeholder="$t('Optional')"></b-input>
</b-field>
<b-tooltip :label="$t('Restart XBR to load new Sites')" :delay="500" type="is-warning">
<b-field>
<b-button type="is-primary" :disabled="!scraperFieldsValid" @click="saveScraper">Save</b-button>
</b-field>
</b-tooltip>
</section>
</div>
</div>
</div>
</div>
</template>

<script>
import ky from 'ky'
export default {
name: 'InterfaceAdvanced',
mounted () {
this.$store.dispatch('optionsAdvanced/load')
},
data () {
return {
activeTab: 0,
scraperUrl: '',
scraperName: '',
scraperCompany: '',
scraperAvatar: '',
scraperFieldsValid: false,
}
},
methods: {
save () {
this.$store.dispatch('optionsAdvanced/save')
}
},
validateScraperFields() {
console.log("validateScraperFields")
this.scraperFieldsValid=false
if (this.scraperName != "") {
if (this.scraperUrl.startsWith("https://") || this.scraperUrl.startsWith("http://") ) {
if (this.scraperUrl.includes("povr.com") || this.scraperUrl.includes("sexlikereal.com") || this.scraperUrl.includes("vrphub.com") || this.scraperUrl.includes("vrporn.com")) {
this.scraperFieldsValid=true
}
}
}
},
saveScraper () {
ky.put('/api/options/custom-sites/create', {
json: {
scraperUrl: this.scraperUrl,
scraperName: this.scraperName,
scraperCompany: this.scraperCompany,
scraperAvatar: this.scraperAvatar
}
})
},
},
computed: {
showInternalSceneId: {
Expand Down

0 comments on commit 72c6834

Please sign in to comment.