-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
06fed7d
commit 4090788
Showing
3 changed files
with
874 additions
and
206 deletions.
There are no files selected for viewing
86 changes: 86 additions & 0 deletions
86
broker/src/main/java/io/moquette/imhandler/GetMediaUploadTokenHandler.java
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,86 @@ | ||
/* | ||
* This file is part of the Wildfire Chat package. | ||
* (c) Heavyrain2012 <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
package io.moquette.imhandler; | ||
|
||
import cn.wildfirechat.common.ErrorCode; | ||
import cn.wildfirechat.proto.WFCMessage; | ||
import com.qiniu.util.Auth; | ||
import com.xiaoleilu.loServer.action.UploadFileAction; | ||
import io.moquette.server.config.MediaServerConfig; | ||
import io.moquette.spi.impl.Qos1PublishHandler; | ||
import io.netty.buffer.ByteBuf; | ||
|
||
@Handler("GMUT") | ||
public class GetMediaUploadTokenHandler extends IMHandler<WFCMessage.GetUploadTokenRequest> { | ||
@Override | ||
public ErrorCode action(ByteBuf ackPayload, String clientID, String fromUser, boolean isAdmin, WFCMessage.GetUploadTokenRequest request, Qos1PublishHandler.IMCallback callback) { | ||
int type = request.getMediaType(); | ||
|
||
String token; | ||
|
||
WFCMessage.GetUploadTokenResult.Builder resultBuilder = WFCMessage.GetUploadTokenResult.newBuilder(); | ||
if (MediaServerConfig.USER_QINIU) { | ||
Auth auth = Auth.create(MediaServerConfig.QINIU_ACCESS_KEY, MediaServerConfig.QINIU_SECRET_KEY); | ||
|
||
|
||
String bucketName; | ||
String bucketDomain; | ||
switch (type) { | ||
case 0: | ||
bucketName = MediaServerConfig.QINIU_BUCKET_GENERAL_NAME; | ||
bucketDomain = MediaServerConfig.QINIU_BUCKET_GENERAL_DOMAIN; | ||
break; | ||
case 1: | ||
bucketName = MediaServerConfig.QINIU_BUCKET_IMAGE_NAME; | ||
bucketDomain = MediaServerConfig.QINIU_BUCKET_IMAGE_DOMAIN; | ||
break; | ||
case 2: | ||
bucketName = MediaServerConfig.QINIU_BUCKET_VOICE_NAME; | ||
bucketDomain = MediaServerConfig.QINIU_BUCKET_VOICE_DOMAIN; | ||
break; | ||
case 3: | ||
bucketName = MediaServerConfig.QINIU_BUCKET_VIDEO_NAME; | ||
bucketDomain = MediaServerConfig.QINIU_BUCKET_VIDEO_DOMAIN; | ||
break; | ||
case 4: | ||
bucketName = MediaServerConfig.QINIU_BUCKET_FILE_NAME; | ||
bucketDomain = MediaServerConfig.QINIU_BUCKET_FILE_DOMAIN; | ||
break; | ||
case 5: | ||
bucketName = MediaServerConfig.QINIU_BUCKET_PORTRAIT_NAME; | ||
bucketDomain = MediaServerConfig.QINIU_BUCKET_PORTRAIT_DOMAIN; | ||
break; | ||
case 6: | ||
bucketName = MediaServerConfig.QINIU_BUCKET_FAVORITE_NAME; | ||
bucketDomain = MediaServerConfig.QINIU_BUCKET_FAVORITE_DOMAIN; | ||
break; | ||
default: | ||
bucketName = MediaServerConfig.QINIU_BUCKET_GENERAL_NAME; | ||
bucketDomain = MediaServerConfig.QINIU_BUCKET_GENERAL_DOMAIN; | ||
break; | ||
} | ||
|
||
token = auth.uploadToken(bucketName); | ||
resultBuilder.setDomain(bucketDomain) | ||
.setServer(MediaServerConfig.QINIU_SERVER_URL); | ||
resultBuilder.setPort(80); | ||
} else { | ||
token = UploadFileAction.getToken(type); | ||
resultBuilder.setDomain("http://" + MediaServerConfig.SERVER_IP + ":" + MediaServerConfig.HTTP_SERVER_PORT) | ||
.setServer(MediaServerConfig.SERVER_IP); | ||
resultBuilder.setPort(MediaServerConfig.HTTP_SERVER_PORT); | ||
} | ||
|
||
resultBuilder.setToken(token); | ||
|
||
byte[] data = resultBuilder.buildPartial().toByteArray(); | ||
ackPayload.ensureWritable(data.length).writeBytes(data); | ||
return ErrorCode.ERROR_CODE_SUCCESS; | ||
} | ||
} |
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
Oops, something went wrong.