-
Notifications
You must be signed in to change notification settings - Fork 1
/
CineastConfig.cs
115 lines (99 loc) · 2.79 KB
/
CineastConfig.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
using System;
using Org.Vitrivr.CineastApi.Client;
namespace Vitrivr.UnityInterface.CineastApi.Model.Config
{
[Serializable]
public class CineastConfig
{
/// <summary>
/// A descriptive name for the connected Cineast.
/// </summary>
public string name;
/// <summary>
/// The host address of cineast.
/// Defaults to http://localhost:4567/
/// </summary>
public string cineastHost;
/// <summary>
/// The host address for media items.
/// Defaults to http://localhost/
/// </summary>
public string mediaHost;
/// <summary>
/// If true, cineast is expected to serve the media as "thumbnails/:s" and "objects/:o", hence we'll try to load them from there
/// </summary>
public bool cineastServesMedia;
/// <summary>
/// The path to thumbnail files.
/// Defaults to "thumbnails/:o/:s"
/// </summary>
public string thumbnailPath;
/// <summary>
/// The thumbnail file extension.
/// Defaults to ".jpg"
/// </summary>
public string thumbnailExtension;
/// <summary>
/// The path to original media files.
/// Defaults to "collection/:p"
/// </summary>
public string mediaPath;
public CineastConfig()
{
// empty constructor
}
public CineastConfig(
string name,
string cineastHost,
string mediaHost,
string thumbnailPath,
string thumbnailExtension,
string mediaPath)
{
this.name = name;
this.cineastHost = SanitizeHost(cineastHost);
this.mediaHost = SanitizeHost(mediaHost);
this.thumbnailPath = thumbnailPath;
this.thumbnailExtension = thumbnailExtension;
this.mediaPath = mediaPath;
}
public bool IsEmpty()
{
return string.IsNullOrEmpty(cineastHost) || string.IsNullOrEmpty(mediaHost);
}
/// <summary>
/// Ensures that the host starts with "http://" and ends with "/"
/// </summary>
/// <param name="host">The host address to sanitize</param>
/// <returns></returns>
private string SanitizeHost(string host)
{
if (string.IsNullOrEmpty(host))
{
return host;
}
if (!(host.StartsWith("http://") || host.StartsWith("https://")))
{
host = "http://" + host;
}
if (!host.EndsWith("/"))
{
host += "/";
}
return host;
}
public static CineastConfig GetDefault()
{
return new CineastConfig("Cineast",
"http://localhost:4567/",
"http://localhost/",
"thumbnails/:o/:s",
".jpg",
"collection/:p");
}
public Configuration GetApiConfig()
{
return new Configuration { BasePath = cineastHost };
}
}
}