-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ feat: extract upload alerts interceptor to a separate service
- Loading branch information
david-vaclavek
committed
Oct 5, 2023
1 parent
c18e535
commit b0ce91c
Showing
9 changed files
with
62 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const LOCALAZY_PLUGIN_CHANNEL = "localazy-plugin"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export const UPLOAD_EVENT = "upload"; | ||
export const UPLOAD_FINISHED_EVENT = "upload:finished"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import SocketIoClient from "socket.io-client"; | ||
import { LOCALAZY_PLUGIN_CHANNEL } from "../constants/channels"; | ||
|
||
|
||
export default class AlertsService { | ||
_client; | ||
|
||
_streamIdentifier; | ||
|
||
constructor() { | ||
this._client = SocketIoClient.connect(process.env.STRAPI_ADMIN_BACKEND_URL); | ||
} | ||
|
||
setStreamIdentifier(streamIdentifier) { | ||
this._streamIdentifier = streamIdentifier; | ||
} | ||
|
||
subscribe(channel = null) { | ||
this._client.emit("subscribe", channel || LOCALAZY_PLUGIN_CHANNEL); | ||
} | ||
|
||
on(event, callback) { | ||
this._client.on(`${event}:${this._streamIdentifier}`, callback); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
admin/src/modules/localazy-upload/services/upload-alerts-service.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import AlertsService from "../../alerts/services/alerts-service"; | ||
import { UPLOAD_EVENT, UPLOAD_FINISHED_EVENT } from "../../alerts/constants/events"; | ||
|
||
export default class UploadAlertsService extends AlertsService { | ||
onUpload(callback) { | ||
this.on(UPLOAD_EVENT, callback); | ||
} | ||
|
||
onUploadFinished(callback) { | ||
this.on(UPLOAD_FINISHED_EVENT, callback); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
LOCALAZY_PLUGIN_CHANNEL: "localazy-plugin", | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module.exports = { | ||
UPLOAD_EVENT: "upload", | ||
UPLOAD_FINISHED_EVENT: "upload:finished", | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters