Skip to content

Commit

Permalink
Fix the remaining Sails V1 upgrade issues (#306)
Browse files Browse the repository at this point in the history
- Make the primary key fields for Asset and Version required and move their initialiation
- Correct the column type for Version.availability
- Fix session.token_secret to session.secret in docker.js
- Use port 8080 instead of 5000 for the default docker config since
  macOS now uses 5000 for AirPlay
- Bump the package.json version to v2.1.2
  • Loading branch information
ArekSredzki authored Dec 21, 2022
1 parent da9f572 commit 6aca5a2
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 20 deletions.
5 changes: 5 additions & 0 deletions api/controllers/AssetController.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,13 @@ module.exports = {
fd: uploadedFile.fd,
size: uploadedFile.size
}, data);

// Due to an API change in Sails/Waterline, the primary key values must be specified directly.=
newAsset.version = newAsset.version.id;

const delta = newAsset.name && newAsset.name.toLowerCase().includes('-delta') ? 'delta_' : '';
newAsset.id = `${newAsset.version}_${newAsset.platform}_${delta}${newAsset.filetype.replace(/\./g, '')}`;

// Create new instance of model using data from params
Asset
.create(newAsset)
Expand Down
14 changes: 3 additions & 11 deletions api/models/Asset.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* Asset.js
*
* @description :: TODO: You might write a short summary of how this model works and what it represents here.
* @description :: A software asset that can be used to install the app (ex. .exe, .dmg, .deb, etc.)
* @docs :: http://sailsjs.org/#!documentation/models
*/

Expand All @@ -13,7 +13,8 @@ module.exports = {

id: {
type: 'string',
unique: true
unique: true,
required: true
},

name: {
Expand Down Expand Up @@ -56,15 +57,6 @@ module.exports = {
type: 'string',
required: true
}
},

beforeCreate: (asset, proceed) => {
const { name, version, platform, filetype } = asset;

const delta = name && name.toLowerCase().includes('-delta') ? 'delta_' : '';
asset.id = `${version}_${platform}_${delta}${filetype.replace(/\./g, '')}`;

return proceed();
}

};
6 changes: 3 additions & 3 deletions api/models/Version.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ module.exports = {
attributes: {
id: {
type: 'string',
unique: true
unique: true,
required: true
},

name: {
Expand All @@ -31,8 +32,7 @@ module.exports = {
},

availability: {
type: 'string',
columnType: 'datetime'
type: 'string'
},

flavor: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ angular.module('app.admin.add-version-modal', [])
$scope.availableFlavors = DataService.availableFlavors;

$scope.version = {
id: '',
name: '',
notes: '',
channel: {
Expand Down Expand Up @@ -34,6 +35,7 @@ angular.module('app.admin.add-version-modal', [])
$scope.availableFlavors = DataService.availableFlavors;

$scope.version = {
id: '',
name: '',
notes: '',
channel: {
Expand Down
1 change: 1 addition & 0 deletions assets/js/core/data/data-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ angular.module('app.core.data.service', [
var version_for_request = version;
version_for_request.channel = version_for_request.channel.name;
version_for_request.flavor = version_for_request.flavor.name;
version_for_request.id = `${version_for_request.name}_${version_for_request.flavor}`;

return $http.post('/api/version', version_for_request)
.then(function(response) {
Expand Down
2 changes: 1 addition & 1 deletion config/docker.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ module.exports = {
session: {
// Recommended: 63 random alpha-numeric characters
// Generate using: https://www.grc.com/passwords.htm
token_secret: process.env['TOKEN_SECRET'],
secret: process.env['TOKEN_SECRET'],
database: process.env['DB_NAME'] || process.env['DATABASE_URL'] && process.env['DATABASE_URL'].split('/')[3],
host: process.env['DB_HOST'] || process.env['DATABASE_URL'] && process.env['DATABASE_URL'].split('@')[1].split(':')[0],
user: process.env['DB_USERNAME'] || process.env['DATABASE_URL'] && process.env['DATABASE_URL'].split('@')[0].split(':')[1].split('/')[2],
Expand Down
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ services:
# Recommended: 63 random alpha-numeric characters
# Generate using: https://www.grc.com/passwords.htm
TOKEN_SECRET: change_me_in_production
APP_URL: 'localhost:5000'
APP_URL: 'localhost:8080'
ASSETS_PATH: '/usr/src/electron-release-server/releases'
depends_on:
- db
ports:
- '5000:80'
- '8080:80'
entrypoint: ./scripts/wait.sh db:5432 -- npm start
volumes:
- ./releases:/usr/src/electron-release-server/releases
Expand Down
4 changes: 2 additions & 2 deletions docs/docker.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ Install [docker](https://www.docker.com/) and [docker-compose](https://github.co
## Localserver

```bash
docker-compose up -d
# open localhost:5000 in browser
docker-compose up
# open localhost:8080 in browser
```

If you use [docker-machine](https://github.com/docker/machine) you should change
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "electron-release-server",
"private": true,
"version": "1.5.2",
"version": "2.1.2",
"description": "A version server for hosting and serving the your electron desktop app releases.",
"dependencies": {
"@sailshq/upgrade": "^1.0.9",
Expand Down

0 comments on commit 6aca5a2

Please sign in to comment.