Overte C++ Documentation
ExternalResource.h
1 //
2 // ExternalResource.h
3 //
4 // Created by Dale Glass on 6 Sep 2020
5 // Copyright 2020 Vircadia contributors.
6 //
7 // Flexible management for external resources (e.g., on S3).
8 //
9 // Distributed under the Apache License, Version 2.0.
10 // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
11 
12 #ifndef overte_ExternalResource_h
13 #define overte_ExternalResource_h
14 
15 #include <QObject>
16 #include <QUrl>
17 #include <QMap>
18 
19 #include <mutex>
20 
21 #include "NetworkingConstants.h"
22 
38 class ExternalResource : public QObject {
39  Q_OBJECT
40 
41 public:
42  static ExternalResource* getInstance();
43  ~ExternalResource(){};
44 
45  /*@jsdoc
46  * <p>An external resource bucket.</p>
47  * <p>The original High Fidelity used "Public", "Content", and "MPAssets" Amazon S3 buckets. The intention is that the
48  * community-run versions of these will keep the original data and structure, and any new additions will be made to
49  * Overte's "Assets" bucket. This should ease the transition from High Fidelity and ensure a clean separation.</p>
50  * @typedef {object} Script.ResourceBuckets
51  * @property {Script.ResourceBucket} Assets - Overte assets.
52  * @property {Script.ResourceBucket} HF_Public - Assets that used to be in High Fidelity's <code>hifi-public</code> Amazon
53  * S3 bucket.
54  * @property {Script.ResourceBucket} HF_Content - Assets that used to be in High Fidelity's <code>hifi-content</code> Amazon
55  * S3 bucket.
56  * @property {Script.ResourceBucket} HF_Marketplace - Assets that used to be in the High Fidelity's <code>mpassets</code>
57  * Amazon S3 bucket. (High Fidelity marketplace.)
58  */
59  /*@jsdoc
60  * <p>An external resource bucket.</p>
61  * <table>
62  * <thead>
63  * <tr><th>Value</th><th>Name</th><th>Description</th>
64  * </thead>
65  * <tbody>
66  * <tr><td><code>0</code></td><td>HF_Public</td><td>Assets that used to be in High Fidelity's <code>hifi-public</code>
67  * Amazon S3 bucket.</td></tr>
68  * <tr><td><code>1</code></td><td>HF_Content</td><td>Assets that used to be in High Fidelity's <code>hifi-content</code>
69  * Amazon S3 bucket.</td></tr>
70  * <tr><td><code>2</code></td><td>HF_Marketplace</td><td>Assets that used to be in the High Fidelity's
71  * <code>mpassets</code> Amazon S3 bucket. (High Fidelity marketplace.)</td></tr>
72  * <tr><td><code>3</code></td><td>Assets</td><td>Overte assets.</td></tr>
73  * </tbody>
74  * </table>
75  * @typedef {number} Script.ResourceBucket
76  */
77  enum class Bucket {
78  HF_Public,
79  HF_Content,
80  HF_Marketplace,
81  Assets
82  };
83  Q_ENUM(Bucket)
84 
85 
102  QUrl getQUrl(Bucket bucket, QString path);
103 
104  QString getUrl(Bucket bucket, QString path) {
105  return ExternalResource::getQUrl(bucket, path).toString();
106  };
107 
113  QString getBase(Bucket bucket);
114 
125  bool setBase(Bucket bucket, const QString& url);
126 
127 private:
128  ExternalResource(QObject* parent = nullptr);
129 
130  std::mutex _bucketMutex;
131 
132  QMap<Bucket, QUrl> _bucketBases {
133  { Bucket::HF_Public, QUrl(NetworkingConstants::HF_PUBLIC_CDN_URL) },
134  { Bucket::HF_Content, QUrl(NetworkingConstants::HF_CONTENT_CDN_URL) },
135  { Bucket::HF_Marketplace, QUrl(NetworkingConstants::HF_MPASSETS_CDN_URL) },
136  { Bucket::Assets, QUrl(NetworkingConstants::OVERTE_CONTENT_CDN_URL) }
137  };
138 };
139 
140 #endif
Definition: ExternalResource.h:38
Q_ENUM(Bucket) QUrl getQUrl(Bucket bucket
QString getBase(Bucket bucket)
Definition: ExternalResource.cpp:89
bool setBase(Bucket bucket, const QString &url)
Definition: ExternalResource.cpp:94