mirror of
https://github.com/stashapp/stash.git
synced 2025-12-17 04:14:39 +03:00
Add check version functionality (#296)
* Add check version functionality * add backend support * add ui support * minor fixes * cosmetic fixes * workaround query refetch not working after network error * revert changes to Makefile after testing is complete * switch to Releases Github API endpoint, add latest Release URL to UI * latest version is only shown in UI when version is available and data is ready * resolve conflict , squash rebase
This commit is contained in:
@@ -66,3 +66,10 @@ query Version {
|
||||
build_time
|
||||
}
|
||||
}
|
||||
|
||||
query LatestVersion {
|
||||
latestversion {
|
||||
shorthash
|
||||
url
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,6 +96,9 @@ type Query {
|
||||
|
||||
# Version
|
||||
version: Version!
|
||||
|
||||
# LatestVersion
|
||||
latestversion: ShortVersion!
|
||||
}
|
||||
|
||||
type Mutation {
|
||||
@@ -136,4 +139,4 @@ schema {
|
||||
query: Query
|
||||
mutation: Mutation
|
||||
subscription: Subscription
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,4 +2,9 @@ type Version {
|
||||
version: String
|
||||
hash: String!
|
||||
build_time: String!
|
||||
}
|
||||
}
|
||||
|
||||
type ShortVersion {
|
||||
shorthash: String!
|
||||
url: String!
|
||||
}
|
||||
|
||||
179
pkg/api/check_version.go
Normal file
179
pkg/api/check_version.go
Normal file
@@ -0,0 +1,179 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/stashapp/stash/pkg/logger"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"runtime"
|
||||
"time"
|
||||
)
|
||||
|
||||
//we use the github REST V3 API as no login is required
|
||||
const apiURL string = "https://api.github.com/repos/stashapp/stash/tags"
|
||||
const apiReleases string = "https://api.github.com/repos/stashapp/stash/releases"
|
||||
const apiAcceptHeader string = "application/vnd.github.v3+json"
|
||||
|
||||
var stashReleases = func() map[string]string {
|
||||
return map[string]string{
|
||||
"windows/amd64": "stash-win.exe",
|
||||
"linux/amd64": "stash-linux",
|
||||
"darwin/amd64": "stash-osx",
|
||||
"linux/arm": "stash-pi",
|
||||
}
|
||||
}
|
||||
|
||||
type githubTagResponse struct {
|
||||
Name string
|
||||
Zipball_url string
|
||||
Tarball_url string
|
||||
Commit struct {
|
||||
Sha string
|
||||
Url string
|
||||
}
|
||||
Node_id string
|
||||
}
|
||||
|
||||
type githubReleasesResponse struct {
|
||||
Url string
|
||||
Assets_url string
|
||||
Upload_url string
|
||||
Html_url string
|
||||
Id int64
|
||||
Node_id string
|
||||
Tag_name string
|
||||
Target_commitish string
|
||||
Name string
|
||||
Draft bool
|
||||
Author githubAuthor
|
||||
Prerelease bool
|
||||
Created_at string
|
||||
Published_at string
|
||||
Assets []githubAsset
|
||||
Tarball_url string
|
||||
Zipball_url string
|
||||
Body string
|
||||
}
|
||||
|
||||
type githubAuthor struct {
|
||||
Login string
|
||||
Id int64
|
||||
Node_id string
|
||||
Avatar_url string
|
||||
Gravatar_id string
|
||||
Url string
|
||||
Html_url string
|
||||
Followers_url string
|
||||
Following_url string
|
||||
Gists_url string
|
||||
Starred_url string
|
||||
Subscriptions_url string
|
||||
Organizations_url string
|
||||
Repos_url string
|
||||
Events_url string
|
||||
Received_events_url string
|
||||
Type string
|
||||
Site_admin bool
|
||||
}
|
||||
|
||||
type githubAsset struct {
|
||||
Url string
|
||||
Id int64
|
||||
Node_id string
|
||||
Name string
|
||||
Label string
|
||||
Uploader githubAuthor
|
||||
Content_type string
|
||||
State string
|
||||
Size int64
|
||||
Download_count int64
|
||||
Created_at string
|
||||
Updated_at string
|
||||
Browser_download_url string
|
||||
}
|
||||
|
||||
//gets latest version (git commit hash) from github API
|
||||
//the repo's tags are used to find the latest version
|
||||
//of the "master" or "develop" branch
|
||||
func GetLatestVersion(shortHash bool) (latestVersion string, latestRelease string, err error) {
|
||||
|
||||
platform := fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH)
|
||||
wantedRelease := stashReleases()[platform]
|
||||
|
||||
branch, _, _ := GetVersion()
|
||||
if branch == "" {
|
||||
return "", "", fmt.Errorf("Stash doesn't have a version. Version check not supported.")
|
||||
}
|
||||
|
||||
client := &http.Client{
|
||||
Timeout: 3 * time.Second,
|
||||
}
|
||||
|
||||
req, _ := http.NewRequest("GET", apiReleases, nil)
|
||||
|
||||
req.Header.Add("Accept", apiAcceptHeader) // gh api recommendation , send header with api version
|
||||
response, err := client.Do(req)
|
||||
|
||||
input := make([]githubReleasesResponse, 0)
|
||||
|
||||
if err != nil {
|
||||
return "", "", fmt.Errorf("Github API request failed: %s", err)
|
||||
} else {
|
||||
|
||||
defer response.Body.Close()
|
||||
|
||||
data, err := ioutil.ReadAll(response.Body)
|
||||
if err != nil {
|
||||
return "", "", fmt.Errorf("Github API read response failed: %s", err)
|
||||
} else {
|
||||
err = json.Unmarshal(data, &input)
|
||||
if err != nil {
|
||||
return "", "", fmt.Errorf("Unmarshalling Github API response failed: %s", err)
|
||||
} else {
|
||||
|
||||
for _, ghApi := range input {
|
||||
if ghApi.Tag_name == branch {
|
||||
|
||||
if shortHash {
|
||||
latestVersion = ghApi.Target_commitish[0:7] //shorthash is first 7 digits of git commit hash
|
||||
} else {
|
||||
latestVersion = ghApi.Target_commitish
|
||||
}
|
||||
if wantedRelease != "" {
|
||||
for _, asset := range ghApi.Assets {
|
||||
if asset.Name == wantedRelease {
|
||||
latestRelease = asset.Browser_download_url
|
||||
break
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
if latestVersion == "" {
|
||||
return "", "", fmt.Errorf("No version found for \"%s\"", branch)
|
||||
}
|
||||
}
|
||||
return latestVersion, latestRelease, nil
|
||||
|
||||
}
|
||||
|
||||
func printLatestVersion() {
|
||||
_, githash, _ = GetVersion()
|
||||
latest, _, err := GetLatestVersion(true)
|
||||
if err != nil {
|
||||
logger.Errorf("Couldn't find latest version: %s", err)
|
||||
} else {
|
||||
if githash == latest {
|
||||
logger.Infof("Version: (%s) is already the latest released.", latest)
|
||||
} else {
|
||||
logger.Infof("New version: (%s) available.", latest)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
"strconv"
|
||||
|
||||
"github.com/99designs/gqlgen/graphql"
|
||||
|
||||
"github.com/stashapp/stash/pkg/logger"
|
||||
"github.com/stashapp/stash/pkg/models"
|
||||
)
|
||||
|
||||
@@ -116,6 +116,21 @@ func (r *queryResolver) Version(ctx context.Context) (*models.Version, error) {
|
||||
}, nil
|
||||
}
|
||||
|
||||
//Gets latest version (git shorthash commit for now)
|
||||
func (r *queryResolver) Latestversion(ctx context.Context) (*models.ShortVersion, error) {
|
||||
ver, url, err := GetLatestVersion(true)
|
||||
if err == nil {
|
||||
logger.Infof("Retrieved latest hash: %s", ver)
|
||||
} else {
|
||||
logger.Errorf("Error while retrieving latest hash: %s", err)
|
||||
}
|
||||
|
||||
return &models.ShortVersion{
|
||||
Shorthash: ver,
|
||||
URL: url,
|
||||
}, err
|
||||
}
|
||||
|
||||
// Get scene marker tags which show up under the video.
|
||||
func (r *queryResolver) SceneMarkerTags(ctx context.Context, scene_id string) ([]*models.SceneMarkerTag, error) {
|
||||
sceneID, _ := strconv.Atoi(scene_id)
|
||||
|
||||
@@ -216,6 +216,7 @@ func Start() {
|
||||
|
||||
go func() {
|
||||
printVersion()
|
||||
printLatestVersion()
|
||||
logger.Infof("stash is listening on " + address)
|
||||
logger.Infof("stash is running at https://" + displayAddress + "/")
|
||||
logger.Fatal(httpsServer.ListenAndServeTLS("", ""))
|
||||
@@ -228,6 +229,7 @@ func Start() {
|
||||
|
||||
go func() {
|
||||
printVersion()
|
||||
printLatestVersion()
|
||||
logger.Infof("stash is listening on " + address)
|
||||
logger.Infof("stash is running at http://" + displayAddress + "/")
|
||||
logger.Fatal(server.ListenAndServe())
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import {
|
||||
Button,
|
||||
H1,
|
||||
H4,
|
||||
H6,
|
||||
@@ -11,10 +12,11 @@ import * as GQL from "../../core/generated-graphql";
|
||||
import { TextUtils } from "../../utils/text";
|
||||
import { StashService } from "../../core/StashService";
|
||||
|
||||
interface IProps {}
|
||||
interface IProps { }
|
||||
|
||||
export const SettingsAboutPanel: FunctionComponent<IProps> = (props: IProps) => {
|
||||
const { data, error, loading } = StashService.useVersion();
|
||||
const { data: dataLatest, error: errorLatest, loading: loadingLatest, refetch, networkStatus } = StashService.useLatestVersion();
|
||||
|
||||
function maybeRenderTag() {
|
||||
if (!data || !data.version || !data.version.version) { return; }
|
||||
@@ -26,23 +28,61 @@ export const SettingsAboutPanel: FunctionComponent<IProps> = (props: IProps) =>
|
||||
);
|
||||
}
|
||||
|
||||
function maybeRenderLatestVersion() {
|
||||
if (!dataLatest || !dataLatest.latestversion || !dataLatest.latestversion.shorthash || !dataLatest.latestversion.url) { return; }
|
||||
if (!data || !data.version || !data.version.hash) {
|
||||
return (
|
||||
<>{dataLatest.latestversion.shorthash}</>
|
||||
);
|
||||
}
|
||||
|
||||
if (data.version.hash !== dataLatest.latestversion.shorthash) {
|
||||
return (
|
||||
<>
|
||||
<strong>{dataLatest.latestversion.shorthash} [NEW] </strong><a href={dataLatest.latestversion.url}>Download</a>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<>{dataLatest.latestversion.shorthash}</>
|
||||
);
|
||||
}
|
||||
|
||||
function renderLatestVersion() {
|
||||
if (!data || !data.version || !data.version.version) { return; } //if there is no "version" latest version check is obviously not supported
|
||||
return (
|
||||
<HTMLTable>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>Latest Version Build Hash: </td>
|
||||
<td>{maybeRenderLatestVersion()} </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><Button onClick={() => refetch()} text="Check for new version" /></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</HTMLTable>
|
||||
);
|
||||
}
|
||||
|
||||
function renderVersion() {
|
||||
if (!data || !data.version) { return; }
|
||||
return (
|
||||
<>
|
||||
<HTMLTable>
|
||||
<tbody>
|
||||
{maybeRenderTag()}
|
||||
<tr>
|
||||
<td>Build hash:</td>
|
||||
<td>{data.version.hash}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Build time:</td>
|
||||
<td>{data.version.build_time}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</HTMLTable>
|
||||
<HTMLTable>
|
||||
<tbody>
|
||||
{maybeRenderTag()}
|
||||
<tr>
|
||||
<td>Build hash:</td>
|
||||
<td>{data.version.hash}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Build time:</td>
|
||||
<td>{data.version.build_time}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</HTMLTable>
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -50,8 +90,11 @@ export const SettingsAboutPanel: FunctionComponent<IProps> = (props: IProps) =>
|
||||
<>
|
||||
<H4>About</H4>
|
||||
{!data || loading ? <Spinner size={Spinner.SIZE_LARGE} /> : undefined}
|
||||
{!!error ? <span>error.message</span> : undefined}
|
||||
{!!error ? <span>{error.message}</span> : undefined}
|
||||
{!!errorLatest ? <span>{errorLatest.message}</span> : undefined}
|
||||
{renderVersion()}
|
||||
{!dataLatest || loadingLatest || networkStatus == 4 ? <Spinner size={Spinner.SIZE_SMALL} /> : <>{renderLatestVersion()}</>}
|
||||
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -195,15 +195,15 @@ export class StashService {
|
||||
});
|
||||
}
|
||||
|
||||
public static useFindGallery(id: string) { return GQL.useFindGallery({variables: {id}}); }
|
||||
public static useFindScene(id: string) { return GQL.useFindScene({variables: {id}}); }
|
||||
public static useFindGallery(id: string) { return GQL.useFindGallery({ variables: { id } }); }
|
||||
public static useFindScene(id: string) { return GQL.useFindScene({ variables: { id } }); }
|
||||
public static useFindPerformer(id: string) {
|
||||
const skip = id === "new" ? true : false;
|
||||
return GQL.useFindPerformer({variables: {id}, skip});
|
||||
return GQL.useFindPerformer({ variables: { id }, skip });
|
||||
}
|
||||
public static useFindStudio(id: string) {
|
||||
const skip = id === "new" ? true : false;
|
||||
return GQL.useFindStudio({variables: {id}, skip});
|
||||
return GQL.useFindStudio({ variables: { id }, skip });
|
||||
}
|
||||
|
||||
// TODO - scene marker manipulation functions are handled differently
|
||||
@@ -215,27 +215,27 @@ export class StashService {
|
||||
];
|
||||
|
||||
public static useSceneMarkerCreate() {
|
||||
return GQL.useSceneMarkerCreate({ refetchQueries: ["FindScene"] });
|
||||
return GQL.useSceneMarkerCreate({ refetchQueries: ["FindScene"] });
|
||||
}
|
||||
public static useSceneMarkerUpdate() {
|
||||
return GQL.useSceneMarkerUpdate({ refetchQueries: ["FindScene"] });
|
||||
public static useSceneMarkerUpdate() {
|
||||
return GQL.useSceneMarkerUpdate({ refetchQueries: ["FindScene"] });
|
||||
}
|
||||
public static useSceneMarkerDestroy() {
|
||||
return GQL.useSceneMarkerDestroy({ refetchQueries: ["FindScene"] });
|
||||
return GQL.useSceneMarkerDestroy({ refetchQueries: ["FindScene"] });
|
||||
}
|
||||
|
||||
public static useListPerformerScrapers() {
|
||||
return GQL.useListPerformerScrapers();
|
||||
public static useListPerformerScrapers() {
|
||||
return GQL.useListPerformerScrapers();
|
||||
}
|
||||
public static useScrapePerformerList(scraperId: string, q : string) {
|
||||
return GQL.useScrapePerformerList({ variables: { scraper_id: scraperId, query: q }});
|
||||
public static useScrapePerformerList(scraperId: string, q: string) {
|
||||
return GQL.useScrapePerformerList({ variables: { scraper_id: scraperId, query: q } });
|
||||
}
|
||||
public static useScrapePerformer(scraperId: string, scrapedPerformer : GQL.ScrapedPerformerInput) {
|
||||
return GQL.useScrapePerformer({ variables: { scraper_id: scraperId, scraped_performer: scrapedPerformer }});
|
||||
public static useScrapePerformer(scraperId: string, scrapedPerformer: GQL.ScrapedPerformerInput) {
|
||||
return GQL.useScrapePerformer({ variables: { scraper_id: scraperId, scraped_performer: scrapedPerformer } });
|
||||
}
|
||||
|
||||
public static useListSceneScrapers() {
|
||||
return GQL.useListSceneScrapers();
|
||||
public static useListSceneScrapers() {
|
||||
return GQL.useListSceneScrapers();
|
||||
}
|
||||
|
||||
public static useScrapeFreeonesPerformers(q: string) { return GQL.useScrapeFreeonesPerformers({ variables: { q } }); }
|
||||
@@ -245,13 +245,14 @@ export class StashService {
|
||||
public static useAllPerformersForFilter() { return GQL.useAllPerformersForFilter(); }
|
||||
public static useAllStudiosForFilter() { return GQL.useAllStudiosForFilter(); }
|
||||
public static useValidGalleriesForScene(sceneId: string) {
|
||||
return GQL.useValidGalleriesForScene({variables: {scene_id: sceneId}});
|
||||
return GQL.useValidGalleriesForScene({ variables: { scene_id: sceneId } });
|
||||
}
|
||||
public static useStats() { return GQL.useStats(); }
|
||||
public static useVersion() { return GQL.useVersion(); }
|
||||
public static useLatestVersion() { return GQL.useLatestVersion({ notifyOnNetworkStatusChange: true, errorPolicy: 'ignore' }); }
|
||||
|
||||
public static useConfiguration() { return GQL.useConfiguration(); }
|
||||
public static useDirectories(path?: string) { return GQL.useDirectories({ variables: { path }}); }
|
||||
public static useDirectories(path?: string) { return GQL.useDirectories({ variables: { path } }); }
|
||||
|
||||
private static performerMutationImpactedQueries = [
|
||||
"findPerformers",
|
||||
@@ -260,6 +261,7 @@ export class StashService {
|
||||
"allPerformers"
|
||||
];
|
||||
|
||||
|
||||
public static usePerformerCreate() {
|
||||
return GQL.usePerformerCreate({
|
||||
update: () => StashService.invalidateQueries(StashService.performerMutationImpactedQueries)
|
||||
@@ -286,7 +288,7 @@ export class StashService {
|
||||
];
|
||||
|
||||
public static useSceneUpdate(input: GQL.SceneUpdateInput) {
|
||||
return GQL.useSceneUpdate({
|
||||
return GQL.useSceneUpdate({
|
||||
variables: input,
|
||||
update: () => StashService.invalidateQueries(StashService.sceneMutationImpactedQueries),
|
||||
refetchQueries: ["AllTagsForFilter"]
|
||||
@@ -303,18 +305,18 @@ export class StashService {
|
||||
];
|
||||
|
||||
public static useBulkSceneUpdate(input: GQL.BulkSceneUpdateInput) {
|
||||
return GQL.useBulkSceneUpdate({
|
||||
variables: input,
|
||||
return GQL.useBulkSceneUpdate({
|
||||
variables: input,
|
||||
update: () => StashService.invalidateQueries(StashService.sceneBulkMutationImpactedQueries)
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public static useScenesUpdate(input: GQL.SceneUpdateInput[]) {
|
||||
return GQL.useScenesUpdate({ variables: { input : input }});
|
||||
return GQL.useScenesUpdate({ variables: { input: input } });
|
||||
}
|
||||
|
||||
public static useSceneDestroy(input: GQL.SceneDestroyInput) {
|
||||
return GQL.useSceneDestroy({
|
||||
return GQL.useSceneDestroy({
|
||||
variables: input,
|
||||
update: () => StashService.invalidateQueries(StashService.sceneMutationImpactedQueries)
|
||||
});
|
||||
@@ -327,22 +329,22 @@ export class StashService {
|
||||
];
|
||||
|
||||
public static useStudioCreate(input: GQL.StudioCreateInput) {
|
||||
return GQL.useStudioCreate({
|
||||
return GQL.useStudioCreate({
|
||||
variables: input,
|
||||
update: () => StashService.invalidateQueries(StashService.studioMutationImpactedQueries)
|
||||
});
|
||||
}
|
||||
|
||||
public static useStudioUpdate(input: GQL.StudioUpdateInput) {
|
||||
return GQL.useStudioUpdate({
|
||||
return GQL.useStudioUpdate({
|
||||
variables: input,
|
||||
update: () => StashService.invalidateQueries(StashService.studioMutationImpactedQueries)
|
||||
});
|
||||
}
|
||||
|
||||
public static useStudioDestroy(input: GQL.StudioDestroyInput) {
|
||||
return GQL.useStudioDestroy({
|
||||
variables: input,
|
||||
return GQL.useStudioDestroy({
|
||||
variables: input,
|
||||
update: () => StashService.invalidateQueries(StashService.studioMutationImpactedQueries)
|
||||
});
|
||||
}
|
||||
@@ -355,22 +357,22 @@ export class StashService {
|
||||
];
|
||||
|
||||
public static useTagCreate(input: GQL.TagCreateInput) {
|
||||
return GQL.useTagCreate({
|
||||
variables: input,
|
||||
return GQL.useTagCreate({
|
||||
variables: input,
|
||||
refetchQueries: ["AllTags"],
|
||||
update: () => StashService.invalidateQueries(StashService.tagMutationImpactedQueries)
|
||||
});
|
||||
}
|
||||
public static useTagUpdate(input: GQL.TagUpdateInput) {
|
||||
return GQL.useTagUpdate({
|
||||
variables: input,
|
||||
return GQL.useTagUpdate({
|
||||
variables: input,
|
||||
refetchQueries: ["AllTags"],
|
||||
update: () => StashService.invalidateQueries(StashService.tagMutationImpactedQueries)
|
||||
});
|
||||
}
|
||||
public static useTagDestroy(input: GQL.TagDestroyInput) {
|
||||
return GQL.useTagDestroy({
|
||||
variables: input,
|
||||
return GQL.useTagDestroy({
|
||||
variables: input,
|
||||
refetchQueries: ["AllTags"],
|
||||
update: () => StashService.invalidateQueries(StashService.tagMutationImpactedQueries)
|
||||
});
|
||||
@@ -506,14 +508,14 @@ export class StashService {
|
||||
public static querySceneByPathRegex(filter: GQL.FindFilterType) {
|
||||
return StashService.client.query<GQL.FindScenesByPathRegexQuery>({
|
||||
query: GQL.FindScenesByPathRegexDocument,
|
||||
variables: {filter: filter},
|
||||
variables: { filter: filter },
|
||||
});
|
||||
}
|
||||
|
||||
public static queryParseSceneFilenames(filter: GQL.FindFilterType, config: GQL.SceneParserInput) {
|
||||
return StashService.client.query<GQL.ParseSceneFilenamesQuery>({
|
||||
query: GQL.ParseSceneFilenamesDocument,
|
||||
variables: {filter: filter, config: config},
|
||||
variables: { filter: filter, config: config },
|
||||
fetchPolicy: "network-only",
|
||||
});
|
||||
}
|
||||
@@ -531,5 +533,5 @@ export class StashService {
|
||||
return value;
|
||||
}
|
||||
|
||||
private constructor() {}
|
||||
private constructor() { }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user